I’m loading in some HTML content like this:
$('#scores').load('scores.php #scores');
Note that It is a requirement that I target a specific part of scores.php (as there is other text surrounding the area I’m trying to target.
However the HTML generated by the load function is not targetable with JQuery.
For example if the #scores html is like this:
<div class="score">2335</div>
The JQuery Event listener doesn’t pickup on this:
$('.score').click(function(event){
/* This doesn't work */
alert('this alert never fires if the click event listener is an ajax generated item.');
});
You’re probably not reactivating the .click event after the data has been loaded into the page. I’ve had this problem myself.
The two solutions I’ve come up with are to use the success callback on the ajax to reactivate the click event (ensuring that it’ll always be live after it’s loaded) or to use the .on(“click”, function()) instead, because it’ll always exist.
edit: changed live to on. force of habit.