Skip to content Skip to sidebar Skip to footer

Cannot Read Property 'addeventlistener' Of Null On Menu

Trying to implement a responsive menu. added script which is as follows (function() { var bodyEl = document.body, content = document.querySelector( '.content-wra

Solution 1:

Most likely the element is not there in the DOM when the script is executing. You will need to call the init method after the DOM has initialized.

Move the script to the bottom after the body tag. or use jquery and call your init method inside $(document).ready().

Also, consider moving the variable initializations to the init method

bodyEl = document.body,
    content = document.querySelector( '.content-wrap' ),
    openbtn = document.getElementById( 'open-button' ),
    closebtn = document.getElementById( 'close-button' )

so that they read the proper values after the dom is loaded, instead of when the script is initialized.

Post a Comment for "Cannot Read Property 'addeventlistener' Of Null On Menu"