WebAIM - Web Accessibility In Mind

E-mail List Archives

Regarding images lacking alts

for

From: Bryan Garaventa
Date: Dec 4, 2012 2:26PM


Hi, I still experience this all over the place on the web, and it's sort of annoying.

Here is a jQuery script that fixes it dynamically, though in a perfect world, it wouldn't be needed.

$('img').each(function(i, o){
var hasAlt = o.getAttributeNode('alt') ? true : false,
hasTitle = o.getAttributeNode('title') ? true : false;
if (!hasAlt) $(o).attr('alt', hasTitle ? o.title : '');
});

It can also be changed to throw an alert during development, such as

if (!hasAlt) alert("Missing Alt attribute: " + o.outerHTML);