Numbering for each div with the same class name



  • There's a code. He's checking everything. div-ы c class="number" and renumbers them. But he replaces the whole text. div The numbering number. How to leave the text in the divine so the numbering would be before the text, like: 1. Какой то текст ?

    jQuery('.number').html(function(i){ return i+1 });
    


  • Own. https://api.jquery.com/html/ works in such a way as to either return or modify the html contents of the selected elements. In your case, you replace the content inside. div Class number to number number number.

    Use the number you need before the content. https://api.jquery.com/prepend/ which will add content inside the selected elements before the existing content.


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2