adam91holt of Acumen Online
11/25/2016 - 1:24 AM

Add Alt attribute to all images if they don't have one by using the file name

Add Alt attribute to all images if they don't have one by using the file name

//Add alt attribute to images if they don't have one by using file name - Adam
$('img').each(function () {
    var $img = $(this)
    if (!$img.attr('alt')) {
        var filename = $img.attr('src')
        $img.attr('alt', filename.substring(filename.lastIndexOf('/') + 1, filename.lastIndexOf('.')))
    }
})