Get a free trial // Grow your CSS skills // Land your dream job

Element number (jQuery)

  • # October 24, 2009 at 3:56 pm

    Hello :) I hope you guys can help me with my little problem. Is it possible with jQuery to add "This like li number x" to the li?

    Let’s say I have this list


    What I want it to do is saying something like this:

    • This is li number 1
    • This is li number 2
    • This is li number 3

    I have searched in a long time and I havn’t found anything yet, so I hope you guys can help me. If you need more details or something, just write ;)


    Here’s an illustration of it

    # October 25, 2009 at 3:49 am

    we need more details. Like why you would want that. Why not just use html to number them? Like an ordered list?


    that would give you numbered li’s

    # October 25, 2009 at 9:24 am

    Ok, I’ve tried to illustrate what it hopefully will end with.


    Hope it makes more sense

    # October 25, 2009 at 1:42 pm

    You can loop through them with jQuery like

    $(“li”).each(function(i) {

    $(this).append(“” + i + ““);


    That will append a span of the number of each list element. Hopefully that’ll work anyway…

    # October 25, 2009 at 5:02 pm

    Thanks! :D :D It works! But is there a way it can start on 1 instead of 0? Is it just best to add an empty li?

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed