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
Solved

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

Posted on 2011-02-23
2
656 Views
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>
</ul>

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
0
Comment
Question by:interclubs
  • 2
2 Comments
 
LVL 15

Expert Comment

by:dirknibleck
ID: 34963073
This might work:


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

Accepted Solution

by:
dirknibleck earned 500 total points
ID: 34963078
Should have been this:

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

861 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