jQuery: Numbering an Unordered List


/ Published in: jQuery
Save to your folder(s)

Here’s a very simple script which adds numbers sequentially to an unordered list using jQuery


Copy this code and paste it in your HTML
  1. <script type="text/javascript"
  2. src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js">
  3. </script>
  4.  
  5. <script type="text/javascript">
  6. $(function () {
  7. $('ul > li').each(function () {
  8. $(this).prepend("(" +
  9. ($(this).index() + 1) + ") ");
  10. });
  11. })
  12. </script>

URL: http://www.devcurry.com/2011/06/jquery-numbering-unordered-list.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.