A
Asbalom
Hello,
The script below was taken from "Javascript & Ajax" by Negrino (pp.
83-84). It was given with just one link. My question is how can I make
it work with more than one link.
// ------------- SCRIPT -------------
window.onload = rolloverInit;
function rolloverInit() {
for (var i=0; i<document.links.length; i++) {
var linkObj = document.links;
if (linkObj.id) {
var imgObj = document.getElementById(linkObj.id + "Img");
if (imgObj) {
setupRollover(linkObj,imgObj);
}
}
}
}
function setupRollover(thisLink,thisImage) {
thisLink.imgToChange = thisImage;
thisLink.onmouseout = rollOut;
thisLink.onmouseover = rollOver;
thisLink.outImage = new Image();
thisLink.outImage.src = thisImage.src;
thisLink.overImage = new Image();
thisLink.overImage.src = "images/" + thisLink.id + "_on.gif";
}
function rollOver() {
this.imgToChange.src = this.overImage.src;
}
function rollOut() {
this.imgToChange.src = this.outImage.src;
}
<!-- ------------- HTML -----------------
<h1><a href="next.html" id="arrow">Next page</a></h1>
<img src="images/arrow_off.gif" width="147" height="82" id="arrowImg"
alt="arrow" />
I appreciate any help. Thanks,
Asbalom
The script below was taken from "Javascript & Ajax" by Negrino (pp.
83-84). It was given with just one link. My question is how can I make
it work with more than one link.
// ------------- SCRIPT -------------
window.onload = rolloverInit;
function rolloverInit() {
for (var i=0; i<document.links.length; i++) {
var linkObj = document.links;
if (linkObj.id) {
var imgObj = document.getElementById(linkObj.id + "Img");
if (imgObj) {
setupRollover(linkObj,imgObj);
}
}
}
}
function setupRollover(thisLink,thisImage) {
thisLink.imgToChange = thisImage;
thisLink.onmouseout = rollOut;
thisLink.onmouseover = rollOver;
thisLink.outImage = new Image();
thisLink.outImage.src = thisImage.src;
thisLink.overImage = new Image();
thisLink.overImage.src = "images/" + thisLink.id + "_on.gif";
}
function rollOver() {
this.imgToChange.src = this.overImage.src;
}
function rollOut() {
this.imgToChange.src = this.outImage.src;
}
<!-- ------------- HTML -----------------
<h1><a href="next.html" id="arrow">Next page</a></h1>
<img src="images/arrow_off.gif" width="147" height="82" id="arrowImg"
alt="arrow" />
I appreciate any help. Thanks,
Asbalom