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

B

bgold12

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
 
J

Joost Diepenmaat

bgold12 said:
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.
 
A

Arun

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.
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,141
Messages
2,570,813
Members
47,357
Latest member
sitele8746

Latest Threads

Top