after():
- In JQuery, after() method is used to insert the data or content at the end as sibling of the element specify by the parameter.
- Syntax:
$(selector).after(content,function(index,html))
Here, we have passed two parameters in the method:
The first one is the content which is a required field with values such as HTML elements, jQuery objects and DOM elements.
The second one is the function(index,html) which is a optional field. It returns the content to insert.
- Example: Suppose we have the following HTML code
<div class='a'>
<div class='b'>b</div>
</div>
Suppose we want to insert div c as the sibling of div a. For this we will use after() method.
$("div.a").after("<div class='c'>C</div>");
The HTML code now look like
<div class='a'>
<div class='b'>b
</div>
<div class='c'>C /<div>----this will be placed here.
0 Comment(s)