Sunday, October 6, 2013

empty, remove, detach. What is the difference ?

jQuery provides various methods to remove elements from DOM. But they all are different from each other, Here's a tiny bit of explanation.


empty() :
-This method is used to remove all the child elements from matched elements.

remove() :
-This method is used to remove all the matched element.
-This method will remove all the jQuery data associated with the matched element.

detach() : 
-This method is same as .remove() method except that the .detach() method doesn’t remove jQuery data associated with the matched elements.

remove() is faster than .empty() or .detach() method.
Related Posts Plugin for WordPress, Blogger...

Receive all updates via Facebook. Just Click the Like Button Below

You can also receive Free Email Updates: