I want to be able to dynamically append to an element that was dynamically appended.
If you have this:
<div id="main">
</div>
$(document).ready(function() {
$('#main').append('<div id="inner"></div>');
$('#inner').append('<div id="goal"></div>');
});
#goal never gets appended. Is there a jquery function to handle this or how would I do it?
Turn it on its head (live copy — there was a bug in the CSS of your example, btw, two
#mainrules and no#innerrule):appendTois kind of the converse ofappend.You can write that more compactly, though (in my view) it’s not worth the loss of clarity (live copy):
Of course, in your precise example, you could just (live copy):
…but I’m guessing you have a reason for doing the two separately.