Posted By

ezerick on 06/19/08


javascript image alt title attribute

Versions (?)

Who likes this?

3 people have marked this snippet as a favorite


Use Image Alt for Image Title

 / Published in: JavaScript

Firefox ignores the alt tag on images and uses the title tag whereas IE uses the alt tag. This javascript code copies the text in all image alts to the image's title. Best when placed at the footer of each page

  1. <script type="text/javascript">
  2. var images = document.getElementsByTagName('img');
  3. for (i = 0; i < images.length; i++)
  4. {
  5. images[i].title = images[i].alt;
  6. }
  7. </script>

Report this snippet  

You need to login to post a comment.