Wednesday, October 25, 2006

WHEN IT DOESN'T WORK - element.setAttribute(...) - javascript


Examples for using element.setAttribute("att_name","att_value") in javascript:
element.setAttribute("src","../Pictures/x.jpg"); // OK, it works.
element.setAttribute("style","cursor: hand;"); // NOT OK, it doesn't work.

So, when trying to add style attributes to elements in javascript, instead of the previous line use:
element.style.setAttribute("cursor","hand",0); // OK, it works.

1 comment:

James said...

Thank you for share knowlede. I try to set it from many example javascript website. But it's not work. Now, I can do it, because your article!

Thank you again.