I understand that $fn.insertAfter() is used to insert element after the element supplied as the argument. How's $fn.after() different from it?
$fn.insertAfter() and $fn.after() Jquery
298 views Asked by Aditya Shukla At
4
There are 4 answers
0
On
Quoting straight from the documentation:
The
.after()and.insertAfter()methods perform the same task. The major difference is in the syntax—specifically, in the placement of the content and target. With.after(), the selector expression preceding the method is the container after which the content is inserted. With.insertAfter(), on the other hand, the content precedes the method, either as a selector expression or as markup created on the fly, and it is inserted after the target container.
$.fn.after()help inserts an element after the target element, on which you call it.whereas,
$.fn.insertAfterinserts the target element after the node you specify:The latter is mostly prefered, because you keep a reference to the newly created element and can chain more methods on it. So for instance:
is possible. You cannot do that with
.after()help. The same thing is for.append()help /.appendTo()help and.insertBefore()help /.before()help