Swap image without name tag.

J

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?

Best regards Joachim
 
R

Richard Cornford

Joachim said:
I have a function that swap images. But in the image element
i use the tag "name"

It is an attribute not a tag.
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.
<snip>

Then you change the function so that it does work. In an XHTML DOM it
should be possible to reference an IDed IMG element through the -
document.images - collection, or use document.getElementById to retrieve
a reference to it.

Richard.
 
M

marss

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';" ....
 
T

Thomas 'PointedEars' Lahn

Joachim said:
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:

"java script"?
<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.

Certainly you don't need or want XHTML 1.1 these times. And most certainly
you do not even need or want XHTML these times. Search the archives.


PointedEars
 
R

Randy Webb

Thomas 'PointedEars' Lahn said the following on 4/28/2006 9:12 AM:
"java script"?

Yes, moron, that is what he said. Your overly pedantic idiotic behavior
is displaying itself again.

And then don't.
Certainly you don't need or want XHTML 1.1 these times. And most certainly
you do not even need or want XHTML these times. Search the archives.

Finally, something that makes sense came from you.
 

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,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top