Q:

How to remove elements from DOM in jQuery

0

How to remove elements from DOM in jQuery

All Answers

need an explanation for this answer? contact us directly to get an explanation for this 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-3.5.1.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>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to remove white spaces from a string in jQuery... >>
<< How to add new elements to DOM in jQuery...