You are loading the Javascript file in the <head>
, before the body of your HTML Is loaded. Therefore your line
const guessSubmit = document.querySelector('.guessSubmit');
Has nothing to look up – your button with class guessSubmit
doesn’t exist yet. And since guessSubmit
is null, it does not contain any properties, hence the error.
The easiest solution is to put your <script>
tag at the bottom of your HTML body rather than the head. This way it will load your Javascript after the DOM is completely loaded.
Alternative ways include adding event listeners to run your script after the DOM is loaded, such as DOMContentLoaded
. See more here: https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded.
Related Posts:
- “Uncaught SyntaxError: Cannot use import statement outside a module” when importing ECMAScript 6
- Failed to load resource: the server responded with a status of 404 (Not Found)
- Failed to load resource: the server responded with a status of 404 (Not Found)
- Maximum call stack size exceeded error
- How to properly use jsPDF library
- Can I use complex HTML with Twitter Bootstrap’s Tooltip?
- What’s the difference between using “let” and “var”?
- Google Chrome Uncaught (in promise) DOMException while playing AUDIO
- How to make a word underline in Markdown
- ChartJS beginAtZero, min, max doesn’t work
- How do I check whether a checkbox is checked in jQuery?
- how to fix : ” TypeError: Cannot read property ‘addEventListener’ of null”…?//
- Cannot set property InnerHTML of null [duplicate]
- ReferenceError: $ is not defined
- React.js: Set innerHTML vs dangerouslySetInnerHTML
- How do I check whether a checkbox is checked in jQuery?
- jQuery document.createElement equivalent?
- (Google Map API) Geocode was not successful for the following reason: REQUEST_DENIED
- How to make a word underline in Markdown
- Pure JavaScript equivalent of jQuery’s $.ready() – how to call a function when the page/DOM is ready for it [duplicate]
- How to play audio?
- How to play audio?
- How can I scroll to an element using jQuery?
- jQuery.click() vs onClick
- jQuery Get Selected Option From Dropdown
- Include another HTML file in a HTML file
- Check if checkbox is checked with jQuery
- Add swipe left/right to web page, but use default swipe up/down
- How to add jQuery code into HTML Page
- How can I get the data-id attribute?
- Check if checkbox is checked with jQuery
- How to import jquery using ES6 syntax?
- How to resolve the C:\fakepath?
- What is the meaning of == $0 that is shown in inspect element of google chrome for the selected element [duplicate]
- Node.js – SyntaxError: Unexpected token import
- Node.js – SyntaxError: Unexpected token import
- Angular: mat-form-field must contain a MatFormFieldControl
- forEach is not a function error with JavaScript array
- (change) vs (ngModelChange) in angular
- Bootstrap Dropdown menu is not working
- Getting Unexpected Token Export
- React with ES7: Uncaught TypeError: Cannot read property ‘state’ of undefined
- jquery SlideToggle effect in upward direction?
- Change Background color (css property) using Jquery
- Using Node.js require vs. ES6 import/export
- Cannot find module ‘@angular-devkit/core’
- Failed to load resource: net::ERR_FILE_NOT_FOUND loading json.js
- Get class name using jQuery
- How to clear the canvas for redrawing
- Adding options to select with javascript
- How can I mock an ES6 module import using Jest?
- Export html table data to Excel using JavaScript / JQuery is not working properly in chrome browser
- Set timeout for ajax (jQuery)
- How does the data-toggle attribute work? (What’s its API?)
- CSS height 100% percent not working
- JavaScript get element by name
- Use images like checkboxes
- How to read xml file contents in jQuery and display in html elements?
- HTML5 Local storage vs. Session storage
- How can I quickly retrieve a value from a MapIterator returned from Object.keys function?
- Completely disable scrolling of webpage
- TypeError: Cannot Set property ‘onclick’ of null
- Express Render not working return error: No default engine was specified and no extension was provided
- How do I scroll to an element using JavaScript?
- Jquery swipe left or right on mobile
- Programmatically change the src of an img tag
- display variable image using cookies
- How to move an element into another element?
- character counter – backspace doesn’t reflect on characters remaining
- Open URL in same window and in same tab
- Create table with jQuery – append
- Error: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of type ‘Node’
- How to scroll to an element?
- How to convert selected HTML to Json?
- ES6: Create Strings using Template Literals – Freecodecamp
- How would I call a javascript function in html?
- How to Open New window on every Click
- Encode HTML entities in JavaScript
- Cannot read property ‘bind’ of undefined. React.js
- “.addEventListener is not a function” why does this error occur?
- Uncaught TypeError: Cannot read property ‘top’ of undefined
- How to move all HTML element children to another parent using JavaScript?
- Cannot read property ‘getContext’ of null, using canvas
- How can I select an element by name with jQuery?
- Full-screen iframe with a height of 100%
- How to add multiple classes to a ReactJS Component?
- Coin toss with JavaScript and HTML
- How to print HTML content on click of a button, but not the page?
- jQuery disable/enable submit button
- How to delay display of page elements until enqueued script has injected html
- how to do open a link in a open window from menu bar? [closed]
- Making the HTML list to a checkbox tree with the plugin jstree [closed]
- Why the images on mi javascript are not found?
- dropdown does not work [closed]
- How do I cycle a JS function in WordPress? [closed]
- Styling parent based on a child element of a child in a WordPress page
- I have custom html mixed with inline javascript that I want added to my WordPress site, how do I achieve this?
- Sending GravityForms to custom HTML
- Processing javascript on wordpress
- How to use Javascript to get data from a WordPress form