var submenus = document.getElementsByClassName("submenu");
for (var i = 0; i < submenus.length; i++) {
submenus[i].onclick = function() {
toggle(submenus[i].nextSibling);
return false;
}
}
function toggle(el) {
if (el.style.display == 'block') {
el.style.display = 'none';
} else {
el.style.display = 'block';
}
}
Causes error: TypeError: submenus[i] is undefined
I assume submenus[i]
is not in the scope of the function. How do I get the element clicked so I can toggle it's next sibling?
No comments:
Post a Comment