Looping Through Elements

<ul>
  <li>Apple</li>
  <li>Banana</li>
  <li>Mango</li>
</ul>

<script>
$(document).ready(function(){
  $("li").each(function(index){
$(this).prepend((index+1) + ". ");
}); }); </script>

.each() loops through all selected elements.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *