How to remove elements from DOM in jQuery

Topic: JavaScript / jQuery« Prev|Next »

Answer: Use the jQuery remove() method

If you want to remove the element itself as well as everything inside it, just use the jQuery remove() method. The following example will show you how remove a paragraph of text form DOM using the jQuery remove() method.

  • <!DOCTYPE html>
  • <html lang="en">
  • <head>
  • <meta charset="utf-8">
  • <title>jQuery Remove Elements from DOM</title>
  • <script type="text/javascript" src="http://code.jquery.com/jquery.js"></script>
  • <script type="text/javascript">
  •     $(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:

 
Close

Your Feedback:

 

We would love to hear from you! Please say something.