Professional Documents
Culture Documents
Alt Text Generator
Alt Text Generator
Alt Text Generator
document.querySelectorAll('img').forEach(function(img) {
// Attach a load event listener to each image
img.addEventListener('load', function() {
var src = img.getAttribute('src') || img.getAttribute('data-src');
var fileNameMatch = src.match(/\/([^\/\?#]+)\.(jpg|jpeg|png|gif|bmp|tiff|
svg|webp)$/i);
if (fileNameMatch && fileNameMatch.length > 1) {
var altText = fileNameMatch[1].replace(/[-_]+/g, ' ').replace(/\b\w/g,
function(char) {
return char.toUpperCase();
});
img.setAttribute('alt', altText);
}
});