Javascript Ajax jQuery Html PHP Example Quiz New MORE

jQuery after() method With Examp

To insert a specified element after a selected element in jQuery after() method is used. It is an inbuilt method of jQuery.

Syntax:

$(selector).after(content,function(index))

Example:

<!DOCTYPE html>  
<html>  
<head>  
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>  
<script>  
$(document).ready(function(){  
    $("button").click(function(){  
        $("p").after("<h1>www.studentstutorial.com</h1>");  
        $("button").hide();
    });  
});  
</script>  
</head>  
<body>  
    <button>Insert content before each p element</button>  
    <p>The below URL is a website for all technology.</</p>  
 
</body>  
</html> 

Run it Yourself »