I am looking to use pure Javascript, not jQuery, to access all elements within a <ul>
list and remove the active class from every item except for the one selected in my menu.
Shown below is the list:
<ul id='flash-menu'>
<li id="menu1" class='something active'>item 1</li>
<li id="menu2" class='somethingelse'>item 2</li>
<li id="menu3" class='somethingelse'>item 3</li>
</ul>
This code snippet contains my JavaScript functionality:
if (x < y){
var listItems = document.getElementById('flash-menu').childNodes;
for (var i=0 ; i<list_items.length ; i++){
list_items[i].className = list_items[i].className.replace('/\bactive\b/','');
}
document.getElementById(view_name).className += " active";
}
The last line of this script successfully adds the active class, but I suspect there may be an issue with how I'm targeting and removing classes from other items. Any helpful suggestions would be greatly appreciated! Thank you!