jQuery has an .after()
method, and also an .insertAfter()
method.
What\'s the difference between them? I think I can use .after()
One important things apart some syntax is that memory leak and performance. insertafter is more efficient than insert when you have tons of dom elements. So prefer insertafter instead of after.
They are inverses of each other. As explained in the jQuery documentation:
This:
$("p").insertAfter("#foo");
Is the same as this:
$("#foo").after("p");
And lastly, insertAfter returns all inserted elements, whereas .after() will return the context it is called on.
$("p").insertAfter("#foo");
==
$("#foo").after("p")
Check the documentation:
$("#foo").after("p")
is the same as:
$("p").insertAfter("#foo");
( after & before ):
$('selector').after('new_content');
$('selector').before('new_content');
while ( insertAfter & insertBefore ):
$('new_content').insertAfter('selector');
$('new_content').insertBefore('selector');