javascript · Technical

JQuery script to change the alt attribute of all images


This is a small script, which change the alt attribute of all img (images) tags on the page:

$(document).ready(function() {

$(“img”).each(function(i) {

this.alt = ‘your new alt text’;

} );

})

Another complex script, which change the alt attribute of all img (images) tags on the page, to the title of the page, if the alt attribute is not set already.

$(document).ready(function() {

var title = $(“title”).html();

$(“img”).each(function(i) {

if(this.alt==”)

this.alt = title;

} );

})

JQuery makes the things as simpler as you cant imagine.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s