Javascript Query

Associate
Joined
3 Oct 2006
Posts
2,304
Location
London
Hi there,

Just wondering you can do a:

document.getElementById("next").src

but can you do a:

document.getElementById("next").onclick

to change the onclick event of an element on the fly?
 
Should work fine. The event handler needs to be a JS function, ie:

Code:
function assign_handler_1() {
  document.sampleImage.onclick=Handler1;  
}

function Handler1() {
alert("Clicked");
}

<a href="javascript:assign_handler_1()">activate handler 1</a>

<img name="sampleImage" width=30 height=20 border=1 src="someimage.gif">

So I assume the getElementById method would be OK, but give it a go :D

Jon
 
Back
Top Bottom