jQuery Remove

jQuery remove elements provide a different method that is used to remove HTML elements or contents.

jQuery provides different methods such as empty(), remove() etc. This method is very helpful for removing HTML elements or contents from the document.

jQuery empty() Method

It is used to remove all the child elements, other descendant elements, and content from the selected element from the dom. Please keep in mind that the selected element remains in the dom.

Source Code

          
            $(document).ready(function () {
  $("button").click(function () {
    $("div").empty();
  });
});          
        
Try it now

jQuery remove() Method

It is used to remove selected elements as well as all the child elements, descendant elements, and their content. Please keep in mind that all the events associated with the HTML element will also be removed from the dom.

Source Code

          
            $(document).ready(function () {
  // Removes paragraphs with class "hint" from DOM
  $("button").click(function () {
    $("p.hint").remove();
  });
});          
        
Try it now

jQuery removeAttr() Method

The jQuery removeAttr() method is used to remove an attribute from the selected elements.

The below, given example will remove the href attribute from the <a> elements on button click.

Source Code

          
            $(document).ready(function () {
  // Removes the hyperlink's href attribute
  $("button").click(function () {
    $("a").removeAttr("href");
  });
});          
        
Try it now

Web Tutorials

jQuery Remove
Html Tutorial HTML
Javascript Tutorial JAVASCRIPT
Css Tutorial CSS
Bootstrap 5 Tutorial BOOTSTRAP 5
Bootstrap 4 Tutorial BOOTSTRAP 4