Moose Senior Member
    member is offline
Joined: Aug 2005 Gender: Male  Posts: 439 Karma: 17 |  | Add image titles to images with alts « Thread Started on Mar 10, 2007, 12:53pm » | |
Basic code, if an image has an alt but not a title, it will receive a title as well. So if some browsers make the alt a screen tip as well and some don't, this can help fix the problem.
Global Footer:
Code:<script type="text/javascript"> <!-- // Add image titles to images with alts var img = document.getElementsByTagName('img'); for(i=0;i<img.length;i++){ if(img[i].alt && img[i].alt != "" && img[i].title == ""){ img[i].title = img[i].alt; } } //--> </script>
|
|
|
Greg says: Coding music... Greg says: Hmm... Greg says: I wouldn't rule it out. Chris 3.0 [New features? Yes.] says:  Greg says: If you think about machine code it's a bunch of 1s and 0s Chris 3.0 [New features? Yes.] says: Anything is possible. Greg says: Yeah try to code Metallica Chris 3.0 [New features? Yes.] says:  Yeah, I'll get right on that... right after I learn to fly. |
|
Aaron [Gone 'til Monday] Coding Helper
     Kay's modest, but friendly...ish, pet. member is offline
![[avatar] [avatar]](http://img844.imageshack.us/img844/10/avvy3.jpg)
woof! =)
Joined: Nov 2006 Gender: Male  Posts: 834 Karma: 13 |  | Re: Add image titles to images with alts « Reply #1 on Mar 10, 2007, 1:50pm » | |
You need to work with your booleans a little more. 
if(img[i].alt && !img[i].title)
| |
|
Moose Senior Member
    member is offline
Joined: Aug 2005 Gender: Male  Posts: 439 Karma: 17 |  | Re: Add image titles to images with alts « Reply #2 on Mar 10, 2007, 9:09pm » | |
Quote:You need to work with your booleans a little more. 
if(img[i].alt && !img[i].title) |
|
I realize you can do that, but I don't how cross browser that is.
|
Greg says: Coding music... Greg says: Hmm... Greg says: I wouldn't rule it out. Chris 3.0 [New features? Yes.] says:  Greg says: If you think about machine code it's a bunch of 1s and 0s Chris 3.0 [New features? Yes.] says: Anything is possible. Greg says: Yeah try to code Metallica Chris 3.0 [New features? Yes.] says:  Yeah, I'll get right on that... right after I learn to fly. |
|
Aaron [Gone 'til Monday] Coding Helper
     Kay's modest, but friendly...ish, pet. member is offline
![[avatar] [avatar]](http://img844.imageshack.us/img844/10/avvy3.jpg)
woof! =)
Joined: Nov 2006 Gender: Male  Posts: 834 Karma: 13 |  | Re: Add image titles to images with alts « Reply #3 on Mar 11, 2007, 4:26am » | |
If an object isn't found (such as an attribute), it returns "undefined." The only cross-browser issue you should ever run in to there (if at all) is if the browser defines a list of common attributes to that element as "" (in which case you'd still recieve a false boolean).
| |
|