Tagged: Images
How can I hide the alt attribute in the images when I mouse over the image?
regards
Hey brunet77,
You can remove the alt attribute using this code (at it on functions.php):
function add_custom_tooltip(){
?>
<script>
jQuery(window).load(function(){
jQuery('a').removeAttr('alt');
jQuery('img').removeAttr('alt');
});
</script>
<?php
}
add_action('wp_footer', 'add_custom_tooltip');
If you’re referring to the tooltip that shows on mouse over, please replace alt with title.
Hope this helps.
Best regards,
Nikko
Sorry, I haven’t explained myself well.
I do not want to delete it.
I want to hide it when I mouse over an image.
I am interested in having the ALT in code, because it is good for SEO.
I guess by CSS there will be some way.
Thank you.
Hi,
Thanks for the clarification, so you mean the little popup which is generated by the browser? If so then that is not something you can control with code unfortunately, you would have to completely remove it.
Best regards,
Rikard
Hi Rikard:
I need hide the alt attribute in the images : “KOTAODO – Alivio duradero del dolor de espalda”
Attach example
regards
Hi brunet77,
Please try this code instead, this should hide the tooltip on image hover:
function add_custom_tooltip(){
?>
<script>
(function($) {
$('img').hover(
function () {
$(this).data('title',$(this).attr('title')).removeAttr('title');
},
function () {
$(this).attr('title',$(this).data('title'));
}
);
})(jQuery);
</script>
<?php
}
add_action('wp_footer', 'add_custom_tooltip', 99);
Best regards,
Nikko
Ok perfect.
Tnks :D
Hi brunet77,
Glad we could help :)
If you need further assistance please let us know.
Best regards,
Victoria