I have created a html and javascript solution to create a toggle list.
HTML is like this:
var coll = document.getElementsByClassName("collapsible");
var i;
for (i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = document.getElementsByClassName("content");
if (content.style.display === "block") {
content.style.display = "none";
} else {
content.style.display = "block";
}
});
}
<button class="collapsible" type="button">tryout</button>
<div class="content">lorem ipum...</div>
I get a notice in the console: "TypeError: content.style is undefined".
I have tried a lot but cannot figure out what i am doing wrong here...