I have created a modal that is triggered when I click on an image from a gallery.
<img class="galleryThumbnail" data-fullsizeImg="assets/gallery/fullsize/apple.jpg" src="assets/gallery/thumbs/tn_apple.jpg" alt="thumbnail">
<img class="galleryThumbnail" data-fullsizeImg="assets/gallery/fullsize/orange.jpg" src="assets/gallery/thumbs/tn_orange.jpg" alt="thumbnail">
<img class="galleryThumbnail" data-fullsizeImg="assets/gallery/fullsize/banana.jpg" src="assets/gallery/thumbs/tn_banana.jpg" alt="thumbnail">
I would like to further this function by getting the data-fullsizeImg file and set that to a variable. Then with that variable set create an tag within the modal window with a src of that data-fullsizeImg. I cannot seem to target the attribute though. I have tried to use this
function createModal() {
var fullsize = $(this).attr('data-fullsizeImg');
console.log($(this).attr('data-fullsizeImg'));
$('#modal').css({
'display': 'block'
});
}
I have also tried this
function createModal() {
var fullsize = $(this).data('fullsizeImg');
console.log($(this).attr('data-fullsizeImg'));
$('#modal').css({
'display': 'block'
});
}
When I do this I get an undefined in the console. What am I doing wrong?
This is what I am using to trigger the function from within HTML if that makes any difference. It does the trick for showing the modal I created
$(".galleryThumbnail").click(function() {
createModal();
});