Introduction:

  • In this article we will explain how to add specified content after the selected element. in jquery
  • or What is after() method in jquery or why use after() method in jquery with example.

  • Description:

The jQuery after() method is used to add specified content after the selected element.

It is just like jQuery append() method. If you want to add content before the selected element,

you should use jQuery before() method.

Syntax:

  • $(selector).after(“content”);

  • Example of jQuery after() method

Let's take an example to demonstrate jQuery after() Method.

<!DOCTYPE html>
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script>
        $(document).ready(function () {
            $("button").click(function () {
                $("p").after("<p><b>sqltutorialspoint.com.com</b></p>");
            });
        });
    </script>
</head>
<body>
    <button>Add content after each p element</button>
    <p>This is a sqltutorials website.</p>
    <p>This is a sqltutorials institute.</p>
</body>
</html>

Output:


In above example when we click on button box "<p><b>sqltutorialspoint.com.com</b></p>"

insert after each of the paragraph.

 

I hope this article will help to you.

0 comments


Leave a comment

Make sure you enter the (*) required information where indicated. HTML code is not allowed.

you may also like