Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 675
  • Last Modified:

Get Order of LI items in a list using JQuery...

I have a list like this:
<ul id="objectListing">
    <li><span class="itemOrder"></span>. Item One</li>
    <li><span class="itemOrder"></span>. Item Two</li>
    <li><span class="itemOrder"></span>. Item Three</li>
    <li><span class="itemOrder"></span>. Item Four</li>

I want to, using JQuery, write a function that grabs all the items, and updates the itemOrder span with the order they appear in. So It would end up giving me this:
    1. Item One
    2. Item Two
    3. Item Three
    4. Item Four
  • 2
1 Solution
This might work:

$("#objectListing li").each(function(id){
     this.children("span").html((id+1) + ".");
Should have been this:

$("#objectListing li").each(function(id){
     $(this).children("span").html((id+1) + ".");
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now