Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Element number (jQuery)

  • This topic is empty.
Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #26548
    Jayj
    Member

    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

    Code:

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

    Code:
    • 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 ;)

    Thanks!

    Here’s an illustration of it
    [img]http://img27.imageshack.us/img27/9413/unavngivetu.png[/img]

    #65885
    cybershot
    Participant

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

    Code:

    that would give you numbered li’s

    #65879
    Jayj
    Member

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

    [img]http://img27.imageshack.us/img27/9413/unavngivetu.png[/img]

    Hope it makes more sense

    #65881
    Chris Coyier
    Keymaster

    You can loop through them with jQuery like

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

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

    });

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

    #65896
    Jayj
    Member

    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)
  • The forum ‘JavaScript’ is closed to new topics and replies.