What is the difference between .empty(), .remove() and .detach() methods in jQuery?



What is the difference between .empty(), .remove() and .detach() methods in jQuery?..

Answer / chaitanya

All these methods .empty(), .remove() and .detach() are used for removing elements from DOM but they all are different.

.empty(): This method removes all the child element of the matched element where remove() method removes set of matched elements from DOM.

.remove(): Use .remove() when you want to remove the element itself, as well as everything inside it. In addition to the elements themselves, all bound events and jQuery data associated with the elements are removed.

.detach(): This method is the same as .remove(), except that .detach() keeps all jQuery data associated with the removed elements. This method is useful when removed elements are to be reinserted into the DOM at a later time.

Find out more here

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More jQuery Interview Questions

How does jquery store data related to an element?

0 Answers  


Can you please explain the difference between body onload() and document.ready() function? : jquery mobile

0 Answers  


How we can get the value of a radio button using jquery?

0 Answers  


what does $("div") will select? : jquery mobile

0 Answers  


Explain some benefits of jquery knockout?

0 Answers  


What is the use of jQuery.ajax method ()?

0 Answers  


Explain the starting point of code execution in jquery? : jquery mobile

0 Answers  


Tell me how to write browser specific code using jquery? : jquery mobile

0 Answers  


How do you update ajax response with id " resilts"?

0 Answers  


What is a jquery library?

0 Answers  


Why is not dom ready working for jquery mobile? : jquery mobile

0 Answers  


What are the various ajax functions?

0 Answers  


Categories