Pixelbox

Welcome to Pixelbox. Friday the 5 of September 2008

Skip to content >>

Problems with setAttribute in IE

Whilst being Pr0 and trying to work around IE's inability to understand the CSS :after class I used JavaScript to add a clearing element after the classes through the DOM, but only for IE. (I know browser sniffing is wrong but if it adds in a clearing element in Opera too there won't be any ill effect).

Anyway I found that Internet Explorer can't add style content through setAttribute and also can't seem to set the class name and then apply the class from the CSS.

After a bit of digging on the web I found that you can use setAttribute("className","clearAll"); to do the same in IE. This works fine but be sure to remember that if Opera or Camino are pretending to be IE they wont add the class name through className so it's worth adding a class in too, just as a back up. (Why can't browsers pretending to be IE not have another navigator element saying their true identity)

Thanks to quirksmode

for the info on this!
Meta tags: Blog, CSS, Hijax, JavaScript

There are no comments yet

Add your own comment