Joachim написав:
Hi.
I have a function that swap images. But in the image element i use the tag
"name" to give name that i send to my java script function:
<img src="greensmiley.jpg" name="smiley" alt="gubbe" onmouseover="swapImage('smiley',
'CoolSmiley.jpg')" onmouseout="swapImage('smiley','greensmiley.jpg')" />
But to have a valid xhtml1.1 document you cant use the "name" tag. I've tried
with the id tag but then my function dont work. Is there any other tag to
use? Or how do you solve this?
You can use "this" keyword in the event handler. "this" is the object
captured event.
html:
<img onmouseover="swapImage(this, 'CoolSmiley.jpg')"
onmouseout="swapImage(this,'greensmiley.jpg')" ....
javascript
:
function swapImage(sender, imgSrc){
sender.src = imgSrc;
}
Or, more simpler:
<img onmouseover="this.src='CoolSmiley.jpg';"
onmouseout="this.src='greensmiley.jpg';" ....