Javascript will not work in child theme with wordpress - TechRepublic
Question
June 13, 2021 at 11:12 AM
spencer1621515293

Javascript will not work in child theme with wordpress

by spencer1621515293 . Updated 5 years, 1 month ago

Hi, could anybody help me figure out why javascript code will not work.
I have put the javascript code in custom-script.js in a child theme, called twentythirteen-child.
And have enqueued it in functions.php and put the html on the wordpess page.
Here is the javascript code:

let counterDisplayElem = document.querySelector(‘.counter-display’);
let counterMinusElem = document.querySelector(‘.counter-minus’);
let counterPlusElem = document.querySelector(‘.counter-plus’);

let count = 0;

updateDisplay();

counterPlusElem.addEventListener(“click”,()=>{
count++;
updateDisplay();
}) ;

counterMinusElem.addEventListener(“click”,()=>{
count–;
updateDisplay();
});

function updateDisplay(){
counterDisplayElem.innerHTML = count;
};

here is the enqueued code in functions.php:

and here is the html in worpress page:

(..)


This discussion is locked

All Comments