Skip to content

Instantly share code, notes, and snippets.

@sand3r
Last active August 29, 2015 14:27
Show Gist options
  • Select an option

  • Save sand3r/38531631752a40ab2bd1 to your computer and use it in GitHub Desktop.

Select an option

Save sand3r/38531631752a40ab2bd1 to your computer and use it in GitHub Desktop.
Detect images in page without (valid) alt and title
var imagecount = 0;
var titleMissing = 0;
var altMissing = 0;
var $image = null;
jQuery('img').each(function(i, el) {
imagecount++;
$image = jQuery(el);
if(typeof $image.attr('title') !== 'undefined' && $image.attr('title') !== '') {
titleMissing++;
}
if(typeof $image.attr('alt') !== 'undefined' && $image.attr('alt') !== '') {
altMissing++;
}
});
console.log(imagecount);
console.log(titleMissing);
console.log(altMissing);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment