Reputation: 8121
I am using fancybox http://fancyapps.com/fancybox/ to add a lightbox popup to my site. I have also added a link under the lightbox pop out image, and am trying to change other things on the page.
If I put the click function into jsfiddle it works just fine :
but when it is clicked from inside the lightbox the click event function isnt triggered :
<script>
$(document).ready(function() {
$(".fancybox-thumb").fancybox({
afterLoad: function() {
this.title = '<a class="selectlink" href="#" id="' + this.title + '">Select This Image</a> ';
},
prevEffect : 'none',
nextEffect : 'none',
helpers : {
title : {
type: 'outside'
},
thumbs : {
width : 50,
height : 50
}
}
});
$('.selectlink').click(function () {
var myId = $(this.id);
alert(this.id);
$('#' + myId).prop('checked', true);
});
});
</script>
This is the html / php
echo '<div class="imagewrapper">';
echo '<a title="'.$row2['id'].'" class="fancybox-thumb" rel="fancybox-thumb" href="albums/'.$albumid.'/800x600/'.$row2['image'].'"><img style="border-radius:5px;" src="albums/'.$albumid.'/thumbnails/'.$row2['image'].'" /></a>';
echo '<div style="text-align:center;">';
echo '<strong>Select : </strong><input class="selectcheckbox" type="checkbox" name="'.$row2['image'].'" id="'.$row2['id'].'" />';
echo '</div>';
echo '</div>';
Upvotes: 1
Views: 2014
Reputation: 8121
I got there in the end with :
$(document).on('click', '.selectlink', function () {
var myId = $('#check_' + this.id);
$(myId).attr('checked', true);
countChecked();
Upvotes: 0
Reputation: 21449
Try:
$(document).on('click', '.selectlink', function () {
var myId = $(this.id);
alert(this.id);
$('#' + myId).prop('checked', true);
});
Basically what happens is the element is not loaded when you set the event handler, but using .on
will delegate event from document to the required element. so the elements that will be added in future also will fire the event.
Upvotes: 3