jQuery empty() vs html("") vs children().remove() | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 3

jQuery empty() vs html("") vs children().remove()

What is the best? Any diference? Best performance, avoiding memory leaks and so on... Do all ways remove attached event handlers, registered data()... ?

8th Jan 2021, 10:55 AM
David Ordás
David Ordás - avatar
1 Antwort
+ 2
The .empty() method will clear the contents of the selected element (let’s say a <div> element), along with the child nodes (if any). The .remove() method will remove the selected element (or the parent element), completely, from the web page. Although, you can save the contents of the removed element, you however cannot retrieve the events or data of the element that you have removed. However, html("") is nothing but displaying nothing.
9th Jan 2021, 10:07 AM
Arun Bhattacharya
Arun Bhattacharya - avatar