Skip to content Skip to sidebar Skip to footer

Difference Between Append And Html In Jquery

What does the difference of html() and append() when it comes to jQuery because if I use append() it will display my data in the next line while if I use html() it will just overwr

Solution 1:

$(el).html() replace everything that is inside the selector.

<divclass="el"><!-- Everything here gets replaced --></div>

$(el).append() puts inside selector at the end.

<divclass="el">
      [...]
      <!-- appends it here --></div>

$(el).prepend() puts inside selector at the begining.

<divclass="el"><!-- preprend it here -->
      [...]
 </div>

$(el).before() puts outside before the selector.

<!-- appends it here --><divclass="el">
      [...]
 </div>

$(el).after() puts outside after selector.

<divclass="el">
      [...]
 </div><!-- appends it here -->

Post a Comment for "Difference Between Append And Html In Jquery"