
JQuery – Popolare il campo “alt” in automatico alle immagini se il campo è vuoto
Salve a tutti,
ecco una piccola guida JQuery su come popolare il campo “alt” in automatico alle immagini se campo è vuoto:
/* Artigiani Del Web – “alt” automatico alle immagini se campo vuoto */
jQuery(‘img’).each(function(){
var img = jQuery(this);
var filename = img.attr(‘src’);
var alt = img.attr(‘alt’);
var name = filename.substring( filename.lastIndexOf(“/”) +1, filename.lastIndexOf(“.”) );
if (alt == “”) {
img.attr(‘alt’, name);
}
});
Tag:jquery
