In this article of Jquery we will learn about Remove Element so Let's start.
@{
ViewBag.Title = "Remove";
}
<h2>Remove</h2>
<!DOCTYPE html>
<html>
<head>
<style>
#firstDiv {
border:1px solid black;
width:200px;
height:200px;
}
#secondDiv {
border: 1px solid black;
width: 200px;
height: 200px;
}
.test {
color:red;
}
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="~/js/Remove.js" type="text/javascript"></script>
</head>
<body>
<!--The jQuery remove() method removes the selected element(s) and its child elements.-->
<h3>The jQuery remove() method removes the selected element(s) and its child elements.</h3>
<div id="firstDiv">
<p>First</p>
<p>Second</p>
</div>
<button id="firstBtn">Enter</button>
<!--End-->
<!--The jQuery empty() method removes the child elements of the selected element(s).-->
<h3>The jQuery empty() method removes the child elements of the selected element(s).</h3>
<div id="secondDiv">
<p>First</p>
<p>Second</p>
</div>
<button id="secondBtn">Enter</button>
<!--End-->
<!--The following example removes all <p> elements with class="test": -->
<h3>The following example removes all <p> elements with class="test": </h3>
<p>This is paragraph</p>
<p class="test">This is some more para</p>
<p class="test">This is some more para</p>
<button id="thirdBtn">Enter</button>
<!--End-->
<script>
$(document).ready(function () {
$("#firstBtn").click(function () {
$("#firstDiv").remove();
});
$("#secondBtn").click(function () {
$("#secondDiv").empty();
});
$("#thirdBtn").click(function () {
$("p").remove(".test")
});
});
</script>
</body>
</html>
Comments
Post a Comment