Home >>jQuery Tutorial >jQuery empty() Method
jQuery empty() method in jQuery is used to removes all content and child nodes from the selected elements. It does not remove the element itself, or its attributes.
Syntax:$(selector).empty()Here is an Example of jQuery empty() Method:
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(".btn1").click(function(){
$("#text").empty();
});
});
</script>
</head>
<body>
<div id="text" style="height:100px;background-color:#5cdafa;">
This is some text
<p>This is a paragraph inside the div.</p>
</div>
<p>This is Phptpoint.</p>
<button class="btn1">click to remove content</button>
</body>
</html>
This is a paragraph inside the div.
This is Phptpoint.