jQuery: Add Numbers into an Ordered List

Posted by qwer0o on Stack Overflow See other posts from Stack Overflow or by qwer0o
Published on 2010-05-23T16:33:40Z Indexed on 2010/05/23 16:40 UTC
Read the original article Hit count: 191

Filed under:

I would like to use jQuery to make this:

<ol>
 <li>item a</li>
 <li>item b</li>
</ol>
<ol>
 <li>item c</li>
 <li>item d</li>
 <li>item e</li>
</ol>

…become this:

<ol>
 <li><span>1</span> item a</li>
 <li><span>2</span> item b</li>
</ol>
<ol>
 <li><span>1</span> item c</li>
 <li><span>2</span> item d</li>
 <li><span>3</span> item e</li>
</ol>

(This answer doesn't work for when there are multiple ols on the page; the number would increment across the ols instead of starting from 1 for each individual ol.)

© Stack Overflow or respective owner

Related posts about jQuery