Javascript examples for jQuery Method and Property:remove
The remove() method removes the selected elements, including all text, child nodes, data and events of the selected elements.
Parameter | Require | Description |
---|---|---|
selector | Optional. | one or more elements to be removed. |
To remove multiple elements, separate them with a comma (,)
The following code shows the difference between the remove() and detach().
<!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ $("#btn1").click(function(){ $("body").append($("#p1").detach()); });//www .j a v a 2 s . com $("#btn2").click(function(){ $("body").append($("#p2").remove()); }); $("p").click(function(){ $(this).animate({fontSize: "+=1px"}) }); }); </script> </head> <body> <p id="p1">Click this paragraph after it is moved - it keeps its click event.</p> <p id="p2">Click this paragraph after it is moved - it does not keeps its click event.</p> <button id="btn1">Detach and append p element</button> <button id="btn2">Remove and append p element</button> </body> </html>