Just a rehash of another SO question.
Calling the jQuery on
method on $(document) and providing the 'selector' option will bind the callback to dynamically added elements matching the selector parameter.
That is, this:
$(document).on('click', 'a', function () {
alert( $(this).attr('class') );
});
instead of this:
$('a').on('click', function () {
alert($(this).attr('class'));
});