+ 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()... ?
1 Resposta
+ 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.