...

View Full Version : Check whether list item is last in list



Michiel
07-27-2006, 01:08 AM
Hi,

I'm working on a script that modifies an unordered list. In de script I loop through an array which contains al list items:


var menuItems = tree.getElementsByTagName('LI');
for(var id=0; id<menuItems.length; id++) {
// modify list items
// e.g.:
menuItems[id].style.backgroundImage = 'url(\'bg_image.jpg\')';
}


Now I'm looking for a way to check whether the current list item is the last element of the tree, in order to assign a different background image to the last list item.

How can I do this?

Thanx! -Michiel

Vladdy
07-27-2006, 02:03 AM
within a loop.

if(id==menuitems.length-1) { }
or loop

for(var id=0; id<menuItems.length-1; id++) {}
then id will be last index



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum