WEB TUTORIALS
PRACTICE EXAMPLES
HTML REFERENCES
CSS REFERENCES
PHP REFERENCES
SPONSORED LINKS
Advertisements

How to remove elements from DOM in jQuery

Topic: JavaScript / jQueryPrev|Next

Answer: Use the jQuery remove() method

You can simply use the jQuery remove() method to remove the elements from DOM. This method will remove the matched elements as well as everything inside of it.

The following example will show you how to remove a paragraph from DOM completely.

  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <meta charset="utf-8">
  • <title>jQuery Remove Elements from DOM</title>
  • <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
  • <script>
  •     $(document).ready(function(){
  •         $("button").click(function(){
  •             $("p").remove(); 
  •         });
  •     });
  • </script>
  • </head>
  • <body>
  •     <button>Remove paragraph</button>
  •     <h1>This is a heading</h1>
  •     <p>This is a paragraph.</p>
  • </body> 
  • </html>

Related FAQ

Here are some more FAQ related to this topic:

Advertisements

Your Feedback:

We would love to hear from you, please drop us a line.