469,593 Members | 2,131 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,593 developers. It's quick & easy.

Whats up with setAttribute on IE

Whats going on with setAttribute on IE it appears to work on some examples
and working code but not on other code that I am writting ?

<style>
.foo {
font-size: 200%;
}
</style>
var e = document.createElement( "div");
e.setAttribute( "class", "foo"); // fails
e.setAttribute( "className", "foo"); // okay
e.setAttribute( "style", "font-size: xx-large"); // fails
e.setAttribute( "style.fontSize", "xx-large"); //fails
e.setAttribute( "style", "font-size: 24pt;"); //fails
e.style.fontSize = '24pt'; // okay
e.className = 'foo'; // okay
e.appendChild( document.createTextNode( "Text Text Text"));
document.body.appendChild( e);

Anyone help fill in the gap in my head !

Many thanks in advance,

Aaron
Feb 10 '07 #1
2 8691
Aaron Gray wrote:
Whats going on with setAttribute on IE it appears to work on some examples
and working code but not on other code that I am writting ?
Don't use setAttribute() for built in attributes, just set the attribute
value.
>
var e = document.createElement( "div");
e.setAttribute( "class", "foo"); // fails
Use e.className.
e.setAttribute( "className", "foo"); // okay
This creates a new attribute.

--
Ian Collins.
Feb 10 '07 #2
VK
On Feb 11, 1:19 am, "Aaron Gray" <ang.use...@gmail.comwrote:
Whats going on with setAttribute on IE it appears to work on some examples
and working code but not on other code that I am writting ?
DOM Tree and DOM interfaces are different things - but there is a
greate confusion on this topic. One of benefits of upcoming HTML 5.0
is that it explains it in details and in proper terms - something that
W3C failed to do in 7 years.
<style>
.foo {
font-size: 200%;
}
</style>

var e = document.createElement( "div");
e.setAttribute( "class", "foo"); // fails
e.setAttribute( "className", "foo"); // okay
e.setAttribute( "style", "font-size: xx-large"); // fails
e.setAttribute( "style.fontSize", "xx-large"); //fails
e.setAttribute( "style", "font-size: 24pt;"); //fails
e.style.fontSize = '24pt'; // okay
e.className = 'foo'; // okay
e.appendChild( document.createTextNode( "Text Text Text"));
document.body.appendChild( e);
function init() {
var elm = document.createElement('div');
elm.appendChild(document.createTextNode('Text'));
elm.className = 'foo';
elm.style.backgroundColor = 'yellow;
document.body.appendChild(elm);
}
window.onload = init;

Feb 11 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by spaminator | last post: by
8 posts views Thread by timmy_dale12 | last post: by
3 posts views Thread by NewmanBT | last post: by
3 posts views Thread by daveland | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.