
Originally Posted by
robertsaunders
If the image that I want to move the mouse over is called 3.gif, [...]
The original filename of any of the images is not important. What is, is the id or name attribute values of the two img elements you want to alter.
Let's assume you have the following three img elements. They're precise location in the document isn't a concern, nor are the attribute values. The first element is your control element, whilst the second and third are the ones to be manipulated.
HTML Code:
<img alt="" src="a.png">
<img id="img1" alt="" src="b1.png">
<img id="img2" alt="" src="c1.png">
In order to alter the images, we need to execute some code in response to the mouseover event. The function we will call, setSource is shown below:
Code:
function setSource() {
for(var j = 0, n = (arguments.length & ~1); j < n; j += 2) {
document.images[j].src = arguments[j + 1];
}
}
This function takes pairs of strings. The first string in each pair is the id or name of the img element, and the second string is a URL (relative or absolute) to the new image resource.
For example (using the markup snippet above):
HTML Code:
<img alt="" src="a.png"
onmouseover="setSource('img1', 'b2.png', 'img2', 'c2.png');">
<img id="img1" alt="" src="b1.png">
<img id="img2" alt="" src="c1.png">
hovering the cursor over the control element would instruct the second image (img1) to display b2.png, and the third image (img2) to display c2.png.
Sorry to be so dim, but java is all still a bit of a mystery to me.
Indeed, as Java and ECMAScript[1] are two completely different languages. Please don't get them confused. We are currently dealing with ECMAScript and the Document Object Model (DOM).
Hope that helps,
Mike
[1] The standardised version of Microsoft's JScript, and Netscape's JavaScript.
Bookmarks