7 Sep 2007 at 17:26 #1 JonB JonB 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?
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?
7 Sep 2007 at 17:39 #2 GeForce GeForce Soldato Joined 14 Feb 2006 Posts 4,644 Location Surrey, UK 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 Jon
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 Jon
9 Sep 2007 at 13:01 #3 Pr0t0c0L Pr0t0c0L Associate Joined 3 Dec 2003 Posts 943 or do it inline document.getElementById("someId").onclick = function () { alert("i have been clicked"); }
or do it inline document.getElementById("someId").onclick = function () { alert("i have been clicked"); }