Studio Zero
« Add image titles to images with alts »

Welcome Guest. Please Login or Register.
Sept 3, 2010, 4:33am





Studio Zero :: Web Development :: Code Storage :: Add image titles to images with alts
   [Search This Thread][Send Topic To Friend] [Print]
 AuthorTopic: Add image titles to images with alts (Read 574 times)
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>
« Last Edit: Mar 10, 2007, 12:53pm by Moose »Link to Post - Back to Top  IP: Logged

Greg says:
Coding music...
Greg says:
Hmm...
Greg says:
I wouldn't rule it out. :P
Chris 3.0 [New features? Yes.] says:
:P
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:
:P 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]

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. :P

if(img[i].alt && !img[i].title)
Link to Post - Back to Top  IP: Logged
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. :P

if(img[i].alt && !img[i].title)

I realize you can do that, but I don't how cross browser that is.
Link to Post - Back to Top  IP: Logged

Greg says:
Coding music...
Greg says:
Hmm...
Greg says:
I wouldn't rule it out. :P
Chris 3.0 [New features? Yes.] says:
:P
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:
:P 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]

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).
Link to Post - Back to Top  IP: Logged
   [Search This Thread][Send Topic To Friend] [Print]


Click Here To Make This Board Ad-Free


This Board Hosted For FREE By ProBoards
Get Your Own Free Message Boards & Free Forums!
Terms of Service | Privacy Policy | Report Abuse | Mobile