Possible Duplicate:
How can I get a reference to a node directly after it is appended?
as an example:
$(document).append('<div class="new-elem" />');
how do i now store the above newly created element into a variable so i can use it like this:
newElem.append('div class="another-new-element" />');
where newElem is the element i appended to the document initially?
i'm assuming it can't be done like:
var newElem = $(document).append('<div class="new-elem" />');
You can do the opposite with appendTo:
var newElem = $('<div class="new-elem" />').appendTo(document);
you should use appendTo:
var newElem = $('<div class="new-elem"></div>').appendTo(document);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With