JQuery Remove
15 - Oct - 2021
XpertPhp
27
In jQuery, there are two types of jQuery methods that are used to remove the elements.
jQuery empty() Method
The jQuery empty() method is used to remove child elements of the specified elements. Example<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#data").empty(); }); }); </script> </head> <body> <div id="data"> <p>This is paragarph tag.</p> <b>This is bold tag.</b> </div> <button>Click here</button> </body> </html>
jQuery remove() Method
The jQuery remove() method is used to remove elements with child elements of the specified elements. Example<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("button").click(function(){ $("#data").remove(); }); }); </script> </head> <body> <div id="data"> <p>This is paragarph tag.</p> <b>This is bold tag.</b> </div> <button>Click here</button> </body> </html>