I'm a novice coder. I want to hover my mouse over an image, and show information. My images have the 'Caption' field filled in, and I want to grab that data to move into the title or data-tooltip.
I am doing my site using Semplice, so it's a Wordpress CMS where I'm limited in what code I can change. I am able to inject custom CSS (globally and on each page) and JavaScript (globally)
I can successfully display prewritten text on hover like this:
jQuery('.semplice-lightbox').hover(function() {
jQuery(this).css('cursor','pointer').attr('title', 'CUSTOM TEXT');
}, function() {
jQuery(this).css('cursor','auto');
});
And I can successfully get the image captions and display them below the image like this:
jQuery('.semplice-lightbox').find('.lightbox-item').wrap('<div>').after(function() {
return jQuery('<p>').text(jQuery(this).attr('caption'));
});
but I'm having trouble understanding how to combine those two things so that I grab the caption and populate another field (like title or data-tooltip) with what I have in my existing caption field.
If it's helpful, here is the data from inspecting the box all this sits in:
<a class="semplice-lightbox"><img class="is-content lightbox-item" src="https://my-website.nfshost.com/wp-content/uploads/2018/04/the-image-filename.jpg" width="1067" height="1600" alt="Alt text" caption="Caption field" data-width="original" data-scaling="no" data-photoswipe-index="0"></a>
Thanks in advance for any help.
$('.semplice-lightbox')is a container of the image, right? - Hikarunomemorythishere doesn't refer to the image, which means you can't get thecaptionfromthis. - Hikarunomemorytitle=""attribute on it? Why do you need jQuery to do this? Can you post example HTML? - TJBlackman