Remove Elements/Content jquery

Remove Elements/Content jquery

  • remove() – Removes the selected element (and its child elements)
  • empty() – Removes the child elements from the selected element

A. remove()

<script>
$(document).ready(function(){
$(“button”).click(function(){
$(“#div1″).remove();
});
});
</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>Remove div element</button>

 

B. empty()

<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>

Leave a Reply