after() and before() in jQuery
after() and before() Methods
after() and before() are similar to append() and before() methods but the difference is that the latter adds content to the current element while the first two insert contents after or before the current elements.
after():-
after() inserts content after the selected elements.
Syntax:-
Its syntax is:- $(selector).after(content, function(index))
Further Explanation:-
Parameter | Description |
---|---|
content | Required. Specifies the content to insert. |
function(index) | Specifies a function that returns the content to insert
|
before():-
before() inserts content before the selected elements.
Syntax:-
Its syntax is:-$(selector).before(content, function(index))
Return:-
Parameter | Description |
---|---|
content | Specifies the content to insert. |
function(index) | Optional. Specifies a function that returns the content to insert
|