<div id="nav2"> <ul> <li></li> <li></li><!-- add class here --> <ul> <li></li> <li><a class="active"></a></li> </ul> <li></li> </ul></div>
var navlinks = document.getElementById('nav2').getElementsByTagName('a'); for (var i = 0; i < navlinks.length; i++) { if(navlinks[i].className == 'active'){ navlinks[i].parentNode.parentNode.parentNode.className = 'YOUR CLASS'; } }
I want to add a class name to the parent li item of li a.active
I need to use raw javascript but I'm just starting out with javascript and this is taking me forever to work out.
Any help would be much appreciated.
Steve
Hope it works, have no idea when i did somthing like that without jquery the last time ^^
That code was what i almost got myself, I must be learning a bit.
Thanks