jQuery remove()

Introduction

Remove all <p> elements:

View in separate window

<!DOCTYPE html>
<html>
<head>
<script 
 src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js">
</script>/*from  w ww .j  ava 2 s . c o  m*/
<script>
$(document).ready(function(){
  $("button").click(function(){
    $("p").remove();
  });
});
</script>
</head>
<body>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

<button>Remove all p elements</button>

</body>
</html>

The remove() method removes the selected elements, including child nodes.

This method also removes data and events of the selected elements.

$(selector).remove(selector)
Parameter
Optional
Description
selector

Optional.

one or more elements to be removed.
To remove multiple elements, separate them with a comma (,)



PreviousNext

Related