Setting onclick() in DOM using Javascript.
by Ramya[ Edit ] 2008-05-15 15:30:56
Setting onclick() in DOM using Javascript.
Using javascript setAttribute(), eventlisteners like onmouseover,onclick in DOM won't work in IE.
hence instead of using,
yy.setAttribute("onclick","somefunction()");
use,
yy.onclick = function() {Javascript: somefunction();};
If you want to display the value of the attribute(ie.value maybe some event) and if you pass the attribute to a function where the event is displayed as,
yy.onclick = function() {Javascript: somefunction('tt');};
it will result as [objectHTML]
To get the value of an attribute using onclick() in DOM,
set the attribute as,
var x = tt.value;