detach() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:detach

Description

The detach() method removes the selected elements, including all text and child nodes, keeps its event handler.

Syntax

The following code shows how to Remove all <p> elements:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").detach();
  });/* ww w .j  a  v a2  s.co  m*/
});
</script>
</head>
<body>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<button>Remove all p elements</button>

</body>
</html>

Related Tutorials