after() Method - Javascript jQuery Method and Property

Javascript examples for jQuery Method and Property:after

Description

The after() method inserts content after the selected elements.

Syntax

$(selector).after(content,function(index));
Parameter RequireDescription
content Required. HTML content or jQuery DOM elements to insert
function(index) Optional a function that returns the content to insert
  • index - Returns the index position of the element in the set

The following code shows how to Insert content after each <p> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").after("<p>Hello world!</p>");
    });//from   w  ww . j a  va2 s  .  c  o m
});
</script>
</head>
<body>

<button>Insert content after each p element</button>

<p>This is a paragraph.</p>
<p>This is another paragraph.</p>

</body>
</html>

Related Tutorials