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)
- Can I use complex HTML with Twitter Bootstrap’s Tooltip?
- How do I check whether a checkbox is checked in jQuery?
- (Google Map API) Geocode was not successful for the following reason: REQUEST_DENIED
- How to make a word underline in Markdown
- How to play audio?
- Check if checkbox is checked with jQuery
- 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?
- Getting Unexpected Token Export
- React with ES7: Uncaught TypeError: Cannot read property ‘state’ of undefined
- Adding options to select with javascript
- How can I mock an ES6 module import using Jest?
- How does the data-toggle attribute work? (What’s its API?)
- How to read xml file contents in jQuery and display in html elements?
- HTML5 Local storage vs. Session storage
- Programmatically change the src of an img tag
- Error: Failed to execute ‘appendChild’ on ‘Node’: parameter 1 is not of type ‘Node’
- ES6: Create Strings using Template Literals – Freecodecamp
- Uncaught TypeError: Cannot read property ‘top’ of undefined
- How can I select an element by name with jQuery?
- Full-screen iframe with a height of 100%
- jQuery disable/enable submit button
- SyntaxError: ‘import’ and ‘export’ may appear only with ‘sourceType: module’ – Gulp
- Parse an HTML string with JS
- Shortest way to print current year in a website
- DOMException: Failed to load because no supported source was found
- Vue is not defined
- OnChange event handler for radio button (INPUT type=”radio”) doesn’t work as one value
- onClick to get the ID of the clicked button
- HTML text input allow only numeric input
- How to change the buttons text using javascript
- How do I use this JavaScript variable in HTML?
- Is it possible to append to innerHTML without destroying descendants’ event listeners?
- How to close current tab in a browser window?
- Why is marquee deprecated and what is the best alternative?
- Refresh/reload the content in Div using jquery/ajax
- How to write inside a DIV box with javascript
- Showing an image from an array of images – Javascript
- This.props.dispatch not a function – React-Redux
- How to get height of div in px dimension
- jQuery: Uncaught Error: Syntax error, unrecognized expression
- SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
- How to use in jQuery :not and hasClass() to get a specific element without a class
- Crop the image using JavaScript
- Adjust width and height of iframe to fit with content in it
- Retrieve the position (X,Y) of an HTML element
- How to display raw JSON data on a HTML page
- How can I copy to clipboard in HTML5 without using flash?
- HTML onchange (this.value)
- How to make an HTML back link?
- How to fix getImageData() error The canvas has been tainted by cross-origin data?
- How to scroll an HTML page to a given anchor
- How do I load an HTML page in a div using JavaScript?
- How do I check if a cookie exists?
- ReactJS – .JS vs .JSX
- how to call a onclick function in tag?
- How do I refresh a DIV content?
- How to implement “select all” check box in HTML?
- How to embed a youtube playlist with a sidebar
- External JavaScript Not Running, does not write to document
- JavaScript button onclick not working
- JavaScript button onclick not working
- Create a simple 10 second countdown
- HTML make text clickable without making it a hyperlink
- Getting HTML form values
- Get the size of the screen, current web page and browser window
- How to run a function when the page is loaded?
- Disabled href tag
- Creating Accordion Table with Bootstrap
- Creating Multiple Modals on a Single Page
- How to enable a disabled checkbox dynamically?
- Closing Bootstrap modal onclick
- .filter is not a function
- When is a CDATA section necessary within a script tag?
- where is create-react-app webpack config and files?
- window.location() not working, not opening page
- How to clear the canvas for redrawing
- How to create checkbox inside dropdown?
- Default text on input
- Adding Google Translate to a web site
- Javascript, viewing [object HTMLInputElement]
- Getting “Cannot call a class as a function” in my React Project
- Why onbeforeunload event is not firing
- How to use aria-expanded=”true” to change a css property
- Error: Couldn’t find preset “es2015” relative to directory “/Users/username”
- How to wrap the content of the main tinyMCE editor with extra tags
- Contact Form 7 – Give each checkbox a class?
- How do developers add “Smooth Transitions” to their sites?
- Building a slide down search box in wordpress
- Do I just put the html in a page when enqueueng or do I also have to reference js file from the html page [closed]
- creating a static HTML/JS/PHP page
- Web cover page open when button clicked
- How to run Javascript popup modal in a loop?
- how to do open a link in a open window from menu bar? [closed]
- I have custom html mixed with inline javascript that I want added to my WordPress site, how do I achieve this?