I am currently working on a feature for an album creation tool where users can select photos from a pool of images and assign them to a specific folder. However, I'm facing difficulty in selecting individual photos and applying customized attributes to them, such as a CSS border style when they are clicked.
Below is the HTML/jQuery code:
HTML
<div class="demo-gallery">
<ul id="lightgallery" class="list-unstyled grid">
<?php foreach ( $media_items as $item ): ?>
<li>
<img class="img-responsive" id="lazy" data-src="<?php echo $item->image_path_sd; ?>">
</li>
<?php endforeach; ?>
</ul>
</div>
Jquery
var picture = document.querySelectorAll('#lazy');
$(picture).each(function () {
$(document).on('click', /*???*/, function () {
if ($(/*???*/).data('clicked', true)) {
$(/*???*/).css("border", "none");
$(/*???*/).data('clicked', false);
} else {
$(/*???*/).css("border", "4px solid #00CE6F");
$(/*???*/).data('clicked', true);
console.log($(/*???*/).data());
}
});
});
I believe that I need to determine the correct placement for the ??? comments, however, I might be approaching this issue incorrectly.
When I use console.log(picture), it returns an array of all the photos. By console.logging(picture[2]), it displays the third image. This is the behavior I desire, but how do I implement these attributes for each photo individually?
In essence, I aim for users to click on photos they wish to select, highlighting them with a bordered outline to indicate their current selection status.