I am trying to toggle multiple divs with same class via one button. At the moment, only the first div is doing the job and the rest gets ignored. I tried to change .getElementById to .getElementsByClassName but it also doesn´t do the trick. Can you please help? Here is my code. I´m trying since 2 days. :/
Code for Button:
<input onclick="change();myFunction()" type="button" value="Zeige Features" id="myButton1"></input>
Code for changing the text of button when clicked to "hide" / "show" (in German):
<script>function change() // no ';' here
{
var elem = document.getElementById("myButton1");
if (elem.value=="Zeige Features") elem.value = "Verstecke Features";
else elem.value = "Zeige Features";
}</script>
The problem should be perhaps here. That´s the code for toggling the divs but only the first div does it:
<script>function myFunction() {
var x = document.getElementById("toggle-div");
if (x.style.display === "block") {
x.style.display = "none";
} else {
x.style.display = "block";
}
} </script>
Hope u can help me, and thanks!