Tuesday, January 18, 2011

Numbered List with Jquery

Obviously you can use an ordered list to create the number in front of a list, however this is often hard to style and cumbersome. Instead jQuery can create a simple numbered list:

<script type="text/javascript">


$("#List li").each(function (i) {

i = i+1;

$(this).prepend('<span class="commentnumber"> '+i+'. </span>');




with the html

<ul id="List">

    <li>first list item</li>

    <li>second list item</li>

    <li>third list item</li>


No comments: