Acute Acute - 5 months ago 36
Javascript Question

jQuery: Can't select just appended element

This is what happens on event:

$('div#pages').append($('<div class="page" id="test">...</div>'));

And then, on another event it fails doing this:

var page = $(''); // returns empty array

I've debugged, and the appended html appears in the document structure after appending, but fails to get selected. Doing the same in browser console works perfectly.

What could be the problem?


Use .find()

var page = $('div#pages').find('');