Archive for the ‘JavaScript’ Category

Programmatic Title Text in Firefox

Thursday, December 7th, 2006

The other day I wrote a very simple script which assigns the ALT TEXT attribute of images to the TITLE attribute, so the behaviour is identical in both Internet Explorer and Firefox.

Run this script after the document has loaded:

function altTextAsTitles() {
// assigns value of image alt text as title text for Firefox
if(document.images) {
var images = document.getElementsByTagName('img');
for(var i = 0; i < images.length; i++) {
if(images[i].alt) {
images[i].title = images[i].alt;
}
}
}
}