SoFunction
Updated on 2025-02-28

Example of insertAfter method usage in jQuery


<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="https:///" />
<title>insertAfter() function-I</title>
<style type="text/css">
p{
  width:100px;
  height:100px;
  border:1px solid red;
}
div{
  width:200px;
  height:200px;
  border:1px solid blue;
}
</style>
<script type="text/javascript" src="mytest/jQuery/jquery-1.8."></script>
<script type="text/javascript">
$(document).ready(function(){
  $("button").click(function(){
    $("div").insertAfter("p");
  })
});
</script>
</head>
<body>
<div>I will be inserted in front of me</div>
<p>I am a p element</p>
<button>Click to view the effect</button>
</body>
</html>