Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


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

Posted on 2011-02-23
Medium Priority
Last Modified: 2012-05-11
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
Question by:interclubs
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 15

Expert Comment

ID: 34963073
This might work:

$("#objectListing li").each(function(id){
     this.children("span").html((id+1) + ".");
LVL 15

Accepted Solution

dirknibleck earned 2000 total points
ID: 34963078
Should have been this:

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

Featured Post

The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question