This is what happens on event:
$(\'div#pages\').append($(\'...\'));
And then, on another eve
Had the same issue, found that if I added the listener before adding the div, it wouldn't find the div. Make sure to add the listener after making the object.