Mouseover events...

U

Uwe Allgäuer

Hi NG!

I want to make my site more dynamic... but i dont find out how this works...

On my site there is at the left side the navigation bar and at the rigt side
i want to put a photo. The photo should change when someone puts the cursor
over the links in the left side.

Does anybody kno how this works?

thx
Uwe
 
T

Tony

Make sure the <img> tag for the photo has an id="" attribute. In the
onmouseover="" attribute of the link you can do something like:

document.getElementById('photoId').src='newphoto.jpg'

This may not exactly work, but at least it points you in the right
direction.
 
U

Uwe Allgäuer

Tony said:
Make sure the <img> tag for the photo has an id="" attribute. In the
onmouseover="" attribute of the link you can do something like:

document.getElementById('photoId').src='newphoto.jpg'

This may not exactly work, but at least it points you in the right
direction.

Boahh, that sounds very good! But i dont know it exactly, because I did not
have much expiriences with javascript how it works...

Is it possible to give with javescript a variable to html? So i could do a
variable with an image and in the html tag i could say something like this:
<img src="var1"...
is this possible?

thx Uwe
 
M

Michael Winter

[snip]
document.getElementById('photoId').src='newphoto.jpg'

The images collection is preferred:

document.images['photoId'].src = '...';
Is it possible to give with javescript a variable to html?

A way was proposed once, but it was never adopted, so no.

[snip]

What you're look for is something like

function setPhoto(url) {
document.images['photoId'].src = url;
}

where 'photoId' is the id attribute value of your main IMG element.

On the links, you'd have

<a ... onmouseover="setPhoto('relative or absolute URL');">

which would change the source of the IMG element to the value of the
string.

Note that this is a very simple approach to the problem.

Hope that helps,
Mike
 
J

Joakim Braun

----- Original Message -----
From: "Uwe Allgäuer said:
Is it possible to give with javescript a variable to html? So i could do a
variable with an image and in the html tag i could say something like this:
<img src="var1"...
is this possible?

No.

In any case you'd still need to update the image path contained in var1
onmouseover, so you wouldn't save any typing (beyond, perhaps, one line).

Joakim Braun
 
U

Uwe Allgäuer

Joakim Braun said:
----- Original Message -----


No.

In any case you'd still need to update the image path contained in var1
onmouseover, so you wouldn't save any typing (beyond, perhaps, one line).

Joakim Braun

Well thanks a lot to all!

I try hard to do this, if there are other questions i will ask again... :)

Thx
Uwe
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top