I've put a google map in a page and it makes lots of img tags without the alt attribute, how can I add the alt for each img in a div in jquery, what's I gotta make instead of :
$('#map_canvas > img[alt]').attr('image');
Thanks
You could do:
$('#map_canvas > img[alt=""]').each(function()
{
$(this).attr('alt', $(this).attr('src');
});
This would find all images within #map_canvas
that do not have an alt
tag, and then set the alt
tag to be the same as the image src
.
Alternatively, I would recommend:
$('#map_canvas > img[alt=""]').attr('alt', 'Alt text');
As this will only add alt tags to images that don't have one.
$('#map_canvas > img').attr('alt', 'alt_text');
To set alternative text to all the images:
$('#map_canvas > img').attr('alt', 'Alternative text');
To set alternative text to images that does not have alt
attribute:
$('#map_canvas > img:not([alt])').attr('alt', 'Alternative text');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With