My simplified code, which should add an EventListener to each b element within my navigation, looks like this:
function openSubNavs2()
{
var allToggleBs = document.querySelector('ul#nav').getElementsByTagName('b');
for (var i=0; i<allToggleBs.length; i++)
{
var toggleB = allToggleBs[i];
toggleB.addEventListener('click', function()
{
toggleB.className = 'show';
});
}
}
window.addEventListener('load', function() {openSubNavs2();});
but the EventListener 'click' is not created.
If I change the increasing allToggleBs[i] to a static allToggleBs[0], the first b element gets the class "show" when clicked - just as expected. The same works with allToggleBs[1] for the second b element.
So basically the b elements are found correctly, but the for loop is not working, and I can't find the reason why.