Well, I'm a truly beginner with javascript, so I have trouble implementing even easiest DOM tricks with it. Actually I think I will place a very simple question here, but whatever, even this one makes me pull my hair out for all day long. I got this horiz. navigation on my page: <ul id="nav"> <li><a href="#">/home</a></li> <li><a href="#">/services</a></li> <li><a href="#">/staff</a></li> <li><a href="#">/products</a></li> <li><a href="#">/contact</a></li> </ul> The nav is dynamic and the list items can change through back end CMS. I have a separators for each of the menu items inserted through css. What I wanna do now is to actually get rid of the last a item separator through javascript. How can I do this? How can I select exactly the last a item from the nav, so I could be able to insert inner style which will delete it's separator "background:none"? Thank you in advance!
var menuLinks; if( document.getElementById('nav') && (menuLinks=document.getElementsByTagName('a')) ) menuLinks[menuLinks.length-1].style.background='none'; Code (markup):
Thanks, but that doesn't work. Anyway I just found a working solution" document.getElementById("nav").getElementsByTagName("LI")[(document.getElementById("nav").getElementsByTagName("LI").length)-1].firstChild.style.backgroundImage = "none"; Code (markup):
Just for the record that should have been: var menuLinks, menu; if( (menu=document.getElementById('nav')) && (menuLinks=menu.getElementsByTagName('a')) ) menuLinks[menuLinks.length-1].style.background='none'; Code (markup):