After and Before Method in jQuery
<!DOCTYPE html>
<html lang="en">
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<title>After and Before Method in jQuery</title>
<style>
body {
font-family: arial
}
#box {
background: lightgreen;
padding: 10px;
border: 1px solid #000;
}
</style>
<body>
<h1>jQuery After & Before Methods</h1>
<div id="box">
<h2>Test Box</h2>
<p>Lorem ipsum <span>dolor, sit amet</span> consectetur adipisicing elit. Quia quasi ex at perspiciatis dolore
dolorum earum totam exercitationem nam? Accusantium sint doloremque qui maxime voluptatum ratione aspernatur
adipisci est incidunt!</p>
</div>
<br>
<button id="afterBtn">After</button>
<button id="beforeBtn">Before</button>
<script src="js/jquery-3.7.1.min.js"></script>
<script>
$(document).ready(function () {
$("#afterBtn").click(function () {
$("#box").after("<h2>This is After Method</h2><p>This is just text</p>");
});
$("#beforeBtn").click(function () {
$("#box").before("<h2>This is Before Method</h2>");
});
});
</script>
</body>
</html>


Comments
Post a Comment