May 15, 2009

Solved problem with setAttribute () in javascript

This week i faced a problem with setAttribute() in javascript, i used this to set a border for an <li> tag when the particular image is clicked.
i used like this,

var LiObj = document.getElementById('img_1');
LiObj.setAttribute("style", "border: 2px solid red;");

this one perfectly works in Mozilla Firefox (since the setAttribute works fine in FF). Same opposite in IE, IE does not support setAttribute(). At this stage what i will do?

i modified the above code like this,

var LiObj = document.getElementById('img_1');
LiObj.style.border = '2px solid red';

This is an simple issue when we look at outside, when there is an deadline on any project this small design issue can trouble your head to lose the hair.

try like this tweaks to fix the browser compatible.

No comments:

Post a Comment