Arjan Eising

Pages

Feeds

You can subscribe to my feeds to get notified when I have written a new post, using RSS or Atom.

Categories

Archives

I wanted to change a CSS value using JavaScript…

…but it did not work in browsers other than Firefox. I looked at my code, it seemed to be okey. I couldn’t use Firebug, since the script worked in Firefox.

After a bit longer looking at my code I found the problem. I used a semicolon inside the string for the CSS. It looked a bit like this: elm.style.display = "none;";. After deleting the semicolon it all worked as intended. A bit weird you cannot use it in this kind of statements, but can when you use the cssText property. And also since you must use it in CSS too.

I made a page in my codex that illustrates the problem. In Firefox it works like expected. IE6 and IE7 both do absolutely nothing useful (they give errors) and other browsers make the text white, but the background not black.

20 responses to I wanted to change a CSS value using JavaScript…

Respond

Post a comment

Like you, I hate spam. So your e-mail address will not be shown on this website, nor sold to the rich and notorious. For your comment you can use the daily XHTML elements: a (do use the title attribute, please), abbr, acronym, blockquote, code, em and strong. Remember, your comment needs to be written in English, and also be an useful addition to the article or other comments. If not, I might want to delete your comment.