shadowayex Posted March 20, 2011 Share Posted March 20, 2011 I have written a small script that is supposed to set the css top property of list items to that of the parent list item's top. The script looks like this: function position(object) { var items = object.childNodes; for (i = 0; i < items.length; i++) { if (items[i].nodeName.toLowerCase() == "li") { items[i].style.top = object.offsetTop + "px"; } } } window.onload = function() { var nav = document.getElementsByTagName("ul")[0]; var items = nav.childNodes; for (i = 0; i < items.length; i++) { if (items[i].nodeName.toLowerCase() == "li") { position(items[i]); } } } I'm rather tired at the moment, and I cannot see anything wrong with this bit of code, although there is obviously something wrong. Does anyone see it? Link to comment Share on other sites More sharing options...
shadowayex Posted March 20, 2011 Author Share Posted March 20, 2011 I figured out the issue. I was using I in both functions, and since I didn't declare them with var, they were using the same i. I changed i = 0 to var i = 0 and it worked. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.