I have a image gallery with a css lightbox. Currently the image gallery is a masonry with lazyload. As the lightbox is a css only one all the images got loaded at the start. So I wanted to force a lazyload on it aswell. So I am trying to force a lazyload only if the image is getting used (clicked on the image in the masonry layout). After i get this working perfectly I can set the same kind of link on the previous and next icons in the lightbox.
But here is the problem. It only works the first time i click on a image. It does not matter wich image, but it only workes once :(
I tried several things but none seems to work.
But the issue remains.
Javascript jquery
$(function() {
$("#image-link").on('click', function() {
var counter = $(this).data('target');
$('.lazybox-' + counter).lazy();
});
});
Html = the counter is to force the lazyload on the specific image
<a id="image-link" href="#<?php echo $id; ?>" data-target="<?php echo $counter; ?>">
<img class="lazy" src=/images/placeholder" data-src="<?php echo base_url($imageLocation); ?>" alt="<?php echo $selected_gallery . ' ' . $counter; ?>">
</a>
I would like to be able to use the javascript function more then once. If at all possible explain why it happend so I can learn, I am a true beginner if it comes to javascript.