Solved

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

Posted on 2011-02-23
2
663 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
[X]
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
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

623 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