Home >Web Front-end >JS Tutorial >jQuery uses the empty() method to delete an element and all its child elements_jquery
The example in this article describes how jQuery uses the empty() method to delete an element and all its child elements. Share it with everyone 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 will be helpful to everyone’s jQuery programming.