jQuery append() - return appended elements

jquery

Solution

There's a simpler way to do this:

$(newHtml).appendTo('#myDiv').effects(...);

This turns things around by first creating `newHtml` with `jQuery(html [, ownerDocument ])`, and then using `appendTo(target)` (note the "`To`" bit) to add that it to the end of `#mydiv`.

Because you now start with `$(newHtml)` the end result of `appendTo('#myDiv')` is that new bit of html, and the `.effects(...)` call will be on that new bit of html too.

Problem

I'm using jQuery.append() to add some elements dynamically. Is there any way to get a jQuery collection or array of these newly inserted elements? So I want to do this: ``` $("#myDiv").append(newHtml); var newElementsAppended = // answer to the question I'm asking newElementsAppended.effects("highlight", {}, 2000); ```

Original source

Related problems