Hi,
I’m working on a small project, but I got stuck.
I want to change classes in my div’s in HTML with JS when I click on buttons, without using the function onclick(), but addEventListener() instead. I have already made it work, but for every DIV I want to change I had a seperate function.
- document.getElementById(“liExample”).addEventListener(“click”, load, true);
- function load()
- {
-
var element1 = document.getElementsByClassName("show-class")[0];
-
element1.classList.remove("show-class");
-
element1.classList.add("hidden-class");
-
var element2 = document.getElementById("EXAMPLE");
-
element2.classList.remove("hidden-class");
-
element2.classList.add("show-class");
- }
…and for every other DIV, I have a separate function.
How do I put a parameter in my first line of code that will be used in my function and will change my EXAMPLE in 7’th line?