(jQuery después) Devolviendo el último objeto insertado

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

preguntado el 08 de noviembre de 11 a las 15:11

What is "after" supposed to return? I can try it and see what happens, but that is hardly a contract. I cannot find any mention of the return value in the docs. api.jquery.com/after Should I assume that all jquery functions will return "this" unless otherwise documented? -

2 Respuestas

Not exactly, but after tiene un amigo insertAfter y before tiene un amigo 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);

respondido 08 nov., 11:19

Thank you. I never checked insertAfter before. lIt works fine. - mr_app

si lo haces :

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

you can get it by :

$('.inner').next()

respondido 08 nov., 11:19

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.