var i = 0
$('#knopToggle').on('click', function () {
i++
var imgAttributes = {
'src': 'kitten' + i + '.jpg',
'title': 'Afbeelding van poes' + i,
'alt': 'Afbeelding van poes' + i
}
if (i > 2) {
i = 0
};
$('#imgKitten').attr(imgAttributes)
}
)
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<img src="kitten1.jpg" alt="" id="imgKitten" height="200px" width="200px">
<div id="divResult"></div>
<button id="knopToggle">wissel afbeelding</button>
it doesn’t show the title with mouseover on images.
How do i get to show the title attribute with mouseover?
2
Answers
Use jquery mouseover event with img element
If you inspect the DOM you’ll see that
title
is not set.You’ll need
element.prop('title', 'something')
to set the Title for a DOM element.Place your mouse over the image, wait 2 seconds and the title will appear:
Keep in mind that you You might not need jQuery, here is the native Javascript version of the above: