Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(jQuery after) Returning last insert Object

Tags:

jquery

Is there a way to return the new inserted object added by the "after" or "before".

like image 962
mr_app Avatar asked Sep 19 '26 06:09

mr_app


2 Answers

Not exactly, but after has a friend insertAfter and before has a friend insertBefore, which do the job you're after, although the signature of the methods are reversed.

Where you'd previous have had:

target.after(element);
target.before(element);

You should now have;

element.insertAfter(target);
element.insertBefore(target);
like image 198
Matt Avatar answered Sep 21 '26 23:09

Matt


if you do :

$('.inner').after('<p>Test</p>');

you can get it by :

$('.inner').next()
like image 38
Royi Namir Avatar answered Sep 21 '26 21:09

Royi Namir