Explain .empty() vs .remove() vs .detach() in Jquery

Sharad Jaiswal
Sharad Jaiswal

Posted On: Feb 22, 2018

 

  • .empty() method is used to remove all the child elements from matched elements.
  • .remove() method is used to remove all the matched element. This method will remove all the jQuery data associated with the matched element.
  • .detach() 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.

Syntax:

$(selector).empty();
$(selector).remove();
$(selector).detach();

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    JQuery Interview Questions

    What is jQuery?

    jQuery is a lightweight JavaScript library which gives a quick and simple method for HTML DOM traversing and manipulati..

    JQuery Interview Questions

    What are the advantages of JQuery ?

    There are many advantages of JQuery. Some of them are :It is more like a JavaScript enhancement so there is no overhea..

    JQuery Interview Questions

    What are the different type of selectors in Jquery?

    There are 3 types of selectors in JqueryCSS Selector XPath Selector Custom Selector..