Search This Blog

Pages

Wednesday, February 16, 2011

Setting onclick() in DOM using Javascript.

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;

No comments:

Post a Comment