As I've discovered with Ajax in jQuery, loaded elements are not jQuery objects. What's the best way to 'rescan' the document to make elements loaded with Ajax jQuery objects?
In the code below jq('.storyBlock button').click(function()
and the other functions do not fire on the loaded Ajax html. How best to change this code so they will fire?
var jq = jQuery.noConflict();
jq(document).ready(function() {
// Disable buttons after clicking
jq('.storyBlock button').click(function() {
jq(this).addClass('selected');
jq(this).parent().addClass('disabled');
jq(this).parent().find('button').attr('disabled', true);
});
// Event Handler
jq('.storyBlock button').click(function() {
// Find link
var getID = jq(this).data('link');
console.log(getID + '.html');
// Load file and insert after last story
jq.ajax(getID + '.html').done(function(html) {
jq('#stories > div:last-child').after(html);
if ( (getID) != 'start' ) {
jq('html,body').animate({ scrollTop: jq('#' + getID).offset().top },'slow');
} else {
jq('.storyBlock').remove();
jq('#stories > div' ).load( "start.html" );
jq('html,body').animate({ scrollTop: jq('#start').offset().top },'slow');
}
});
});
});