When I pressed a button to clear the content in the textarea, the console log gives me an error Uncaught TypeError: Cannot read property ‘addEventListener’ of undefined
I am trying to convert this site http://buildandtest.atspace.cc/ into twentysixteen child theme. It appears that /js/menu.js in my child theme is not working as nothing happens when the ham icon button is clicked (pls.see my site link above to check correct behavior). On inspecting via Google Chrome Inspect I am getting the following errors:
Uncaught TypeError: Cannot read property ‘classList’ of null at mediaqueryresponse (menu.js?ver=5.3.2:19) at menu.js?ver=5.3.2:10 at menu.js?ver=5.3.2:31 mediaqueryresponse @ menu.js?ver=5.3.2:19 (anonymous) @ menu.js?ver=5.3.2:10 (anonymous) @ menu.js?ver=5.3.2:31
(function () {
var mql = window.matchMedia("screen and (max-width: 960px)");
//detect media query
var navTop = document.querySelector(".header");
//return first element within the document that matches .header
var toggle = document.querySelector(".ham-icon");
mediaqueryresponse(mql);
//ensures that addListener function is executed when the page loads, by default addListener only fires when state of the window changes
mql.addListener(mediaqueryresponse);
function mediaqueryresponse(mql) {
if (mql.matches) {
toggle.addEventListener("click", clickMenu);
//if media query matches, execute click or clickMenu event
} else {
navTop.classList.remove("responsive");
//otherwise remove .responsive
toggle.removeEventListener("click", clickMenu);
//and remove EventListener
}
}
function clickMenu() {
navTop.classList.toggle("responsive");
}
})();
The above code did work when I used with a theme created from scratch, however, its not working with child theme.
I currently only have WordPress set up on my local Windows machine running WAMP server. I guess I would have to try move it to my webhost and then try provide the live link… Would it work ?