alt tags in images

R

Rick

how would you create a function in the following script that would
change the alt description of the image via a mouseover event. See
end of script. Thanks in advance.

RICK

<script language="JavaScript">
var i = 1;
banner1= new Image();
banner1.src = "image1.jpg";
banner2= new Image();
banner2.src = "image2.jpg";



var links = new Array

links[1] = "http://www.centerforplantconservation.org/testing/image1.jpg"
links[2] = "http://www.centerforplantconservation.org/testing/image2.jpg"

function loadBanner(){

var time= new Date();
hours= time.getHours();
mins= time.getMinutes();
secs= time.getSeconds();
closeTime=hours*3600+mins*60+secs;

// Change this number to increase decrease the rotation speed
closeTime+=3;

Timer();

}

function Timer(){
var time= new Date();
hours= time.getHours();
mins= time.getMinutes();
secs= time.getSeconds();
curTime=hours*3600+mins*60+secs
if (curTime>=closeTime){
if (i < 5){
i++;
document.banner.src = eval("banner" + i +
".src");
}
else{
i = 1;
document.banner.src = eval("banner" + i +
".src");
} loadBanner();
}
else{
window.setTimeout("Timer()",1000)}

}

function clickLink(){
top.location = links
}

function altimage() {
var ???????
????????????
}


</script>
 
E

Evertjan.

Vjekoslav Begovic wrote on 08 aug 2003 in comp.lang.javascript:
To change alt attribute of image:

myImage.setAttribute("alt", "MyAltText");

Slightly OT-ing the OP:

<img src="..."
alt="this is my standard alt text"
standard="this is my standard alt text"
alternative="this is my alternative alt text"
onclick="this.alt=(this.alt==this.alternative)?
this.standard:this.alternative"
IE6 tested
 
R

Richard Cornford

Slightly OT-ing the OP:

<img src="..."
alt="this is my standard alt text"
standard="this is my standard alt text"
alternative="this is my alternative alt text"
onclick="this.alt=(this.alt==this.alternative)?
this.standard:this.alternative"
IE6 tested

It is very questionable whether adding your own HTML attributes is a
good idea (it should certainly make validating a page against a standard
HTML DTD troublesome).

However, if this technique is used, it is worth mentioning that a number
of browsers do not follow IE in making these attributes into named
properties of the element. They are often (but not always) made
available as attribute nodes so slightly wider browser support can be
achieved by exclusively using the - getAttribute - method of the element
when accessing this type of made up HTML attribute.

Obviously support for providing this type of additional data can be
increased to 100% of JavaScript capable/enabled browsers merely by
defining the data in the JavaScript code (in whatever data structure
suites the problem).

The original question seems to be an attempt to use the ALT attribute as
a vehicle for tool-tip type information. This is widely considered to be
an inappropriate use of the ALT attribute, encouraged by the fact that
some user agents present the contents of the ALT attribute in a tool-tip
style pop-up box. The regulars on HTML groups will usually try to
convince people that the TITLE attribute is the correct vehicle for
tool-tip type information and that the ALT attribute should be a text
alternative to the image, so it would only make sense to change the ALT
attribute text if the image was also swapped.

Richard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top