first need to find all img in the sites
$(\"#body\").find(img)
and then check if the img have the \"alt\" attribute, if image have the attribut
var arr = ['hello', 'hi', 'yo']; $('#body img').each(function() { if ( ! $(this).attr('alt')) $(this).attr('alt', arr[Math.round(Math.random() * (arr.length - 1)))]); });