Whenever I click a button on my wordpress page, it triggers a function called "hideConstruction()" to hide all elements with the class ".construction". However, instead of achieving the intended result, I'm faced with the error message:
"Cannot set property 'visibility' of undefined"
Below is the code snippet that I embedded in my wordpress's script.js file, which is enqueued through functions.php:
function hideConstruction() {
var elements = document.getElementsByClassName("construction");
for (var i = 0; i < elements.length; i++) {
elements[i].style.visibility = "hidden";
}
}
If you'd like to see where this issue is occurring, check out this page:
Any insights into what I might be overlooking would be greatly appreciated. Thank you!