need to change src attr of a destination image from one this clicked on

D

deepsnow

Hi Group,

Inside of an img tag I have an onclick that fires a function. The
function is supposed to change the src of a larger image elsewhere on
the page. Think: click the thumbnail to see it at the enlarged_image
that is on the page.

I tried this function but it doesnt work =/

function doit(){
var node = this;
var nodesrc = node.getAttribute("src");
dest_img.setAttribute("src", nodesrc);
}

I dont think 'this' is doing what I want it to, plus I get the error
that node.getAttribute() is not a function.

Please can someone offer some direction on how I can solve this
problem?
Thanks in advance for any help.

Regards,
DE
 
M

marss

Hi Group,

Inside of an img tag I have an onclick that fires a function. The
function is supposed to change the src of a larger image elsewhere on
the page. Think: click the thumbnail to see it at the enlarged_image
that is on the page.

I tried this function but it doesnt work =/

function doit(){
var node = this;
var nodesrc = node.getAttribute("src");
dest_img.setAttribute("src", nodesrc);

}

I dont think 'this' is doing what I want it to, plus I get the error
that node.getAttribute() is not a function.

Please can someone offer some direction on how I can solve this
problem?
Thanks in advance for any help.

Regards,
DE

Try this
<img src="some.gif" onclick="doit(event)">

function doit(e)
{
var node = e.target || e.srcElement;
var nodesrc = node.src;
dest_img.src = nodesrc;
}

Mykola
http://marss.co.ua
 
P

pr

deepsnow said:
function doit(){
var node = this;
var nodesrc = node.getAttribute("src");
dest_img.setAttribute("src", nodesrc);
}
'this' in this instance probably refers to the window. Try

<img src="x" onclick="doit(this)"/>

and

function doit(node) {...

to get the node you expect.
 

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,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top