Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jul 2002
    Location
    The Netherlands
    Posts
    252
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Check whether list item is last in list

    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:
    Code:
    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

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    Nashua, NH
    Posts
    1,724
    Thanks
    0
    Thanked 0 Times in 0 Posts
    within a loop.
    Code:
    if(id==menuitems.length-1) {  }
    or loop
    Code:
    for(var id=0; id<menuItems.length-1; id++) {}
    then id will be last index
    Vladdy | KL
    "Working web site is not the one that looks the same on common graphical browsers running on desktop computers, but the one that adequately delivers information regardless of device accessing it"


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •