jQuery USES the empty of method to delete an element and all its child elements

  • 2020-05-19 04:15:29
  • OfStack

This example shows how jQuery USES the empty() method to delete an element and all its child elements. Share with you for your reference. The specific implementation method is as follows:


<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
 $("button").click(function(){
  $("#div1").empty();
 });
});
</script>
</head>
<body>
<div id="div1" style="height:100px;width:300px;border:1px solid black;background-color:yellow;">
This is some text in the div.
<p>This is a paragraph in the div.</p>
<p>This is another paragraph in the div.</p>
</div>
<br>
<button>Empty the div element</button>
</body>
</html>

I hope this article has been helpful to your jQuery programming.


Related articles: