Friday, 27 September 2013

How to select nested UL element without class in JavaScript

How to select nested UL element without class in JavaScript

In my Joomla template I've created a vertical menu including a dropdown
which should "push" the elements below away when opening a submenu
onclick. Somehow I don't get it to work..
I am trying to grab the UL inside an LI, but how can I do this in
JavaScript without the UL's having a class or ID.
I've come to this yet:
function getElements(){
var listitems = {};
for(var i = 0; i< arguments.length; i++){
var id = arguments[i];
var item = content.getElementsByTagName("li");
if (item == null)
throw new Error ("No list items found.");
listitems[id] = item;
}
return listitems;
}
Now I should get something like: (I now the following code is impossible,
but it describes what I am trying)
var nav = document.getElementById("navigation");
var nestedList = nav ul li ul.onclick(nav ul li ul.style = "display:
block";);
Thanks!

No comments:

Post a Comment