Connecting Tech Pros Worldwide Help | Site Map

IE support of javascript setAttribute('style', ... )

bgold12
Guest
 
Posts: n/a
#1: Sep 1 '08
Does internet explorer support the statement
elem.setAttribute('style', ... );, for example:

document.getElementById('ExampleID').setAttribute( 'style', 'width:
10px' );

I can't get that statement to work in IE7, although it works in FF3.

bgold12
Joost Diepenmaat
Guest
 
Posts: n/a
#2: Sep 1 '08

re: IE support of javascript setAttribute('style', ... )


bgold12 <bgold12@gmail.comwrites:
Quote:
Does internet explorer support the statement
elem.setAttribute('style', ... );, for example:
That would be a confusing statement: does it completely replace all
current styles or what? Note that FF (at least FF 2) does not allow
you to replace the style, so elem.style = ... will throw an error.

You probably want just elem.style.backgroundColor= ... and equivalent
instead.

--
Joost Diepenmaat | blog: http://joost.zeekat.nl/ | work: http://zeekat.nl/
Arun
Guest
 
Posts: n/a
#3: Sep 1 '08

re: IE support of javascript setAttribute('style', ... )


On Sep 1, 2:46*pm, Joost Diepenmaat <jo...@zeekat.nlwrote:
Quote:
bgold12 <bgol...@gmail.comwrites:
Quote:
Does internet explorer support the statement
elem.setAttribute('style', ... );, for example:
>
That would be a confusing statement: does it completely replace all
current styles or what? Note that FF (at least FF 2) does not allow
you to replace the style, so elem.style = ... will throw an error.
I disagree. Firefox has support for both forms of *style*
manipulation.
You can change the object's complete style description using the
setAttribute(attrName, attrValue) method. But, for the sake of browser
compatibility what you suggested below is more apt.
Quote:
You probably want just elem.style.backgroundColor=... and equivalent
instead.
On another note, Firefox has another way of manipulating attributes
which
is a bit daunting. I was so hoping that IE had it. But 6 and 7 don't
support proper attribute manipulation I might say.

document.getElementById(id).attributes.item("style ").nodeValue =
"color:red";

IE8x, I hope would resolve these issues.

Arun
Closed Thread