YaK:: WebLog #535 Topic : 2007-08-27 06.47.33 matt : javascript fun fact : sticking the wrong things into style properties will silently fail (almost) [Changes]   [Calendar]   [Search]   [Index]   [PhotoTags]   
  [Back to weblog: pretention]  

javascript fun fact: sticking the wrong things into style properties will silently fail (almost)

Some major head scratching with my pair this week when a style.height assignment in JavaScript just wasn't taking hold.

xian and I were working on a JavaScript-heavy web application and ran into a befuddling problem. Our JsUnit test was asserting that the height of an element would change, but it just wasn't happening. We tried Shift+Reload, restarting the browser, restarting IntelliJ, and a bunch of other things that didn't help. We asked another co-worker and he immediately saw the problem in our code.

divElement.style.height = 200;

This is, of course, totally bogus. Firefox 1.5 and 2.0 both just silently drop that line of the CSS. Of course, when turning on CSS Warnings in Firebug , it verified what our coworker had told us.

The code should have readL

divElement.style.height = '200px';

When working for a previous client, I had found that Mozilla 1.7 would let you know about this kind of breakage in a more obvious way. For that reason, we would sometimes run our JsUnit test under Mozilla 1.7 if we ever ran into some unexplainable behaviour in Firefox. I had forgotten that while working with xian, for some reason.

At the same previous client, we also found that turning on CSS Warnings was way too noisy due to lots of little issues in the CSS. As such, it wasn't very useful. Eventually, we went through and fixed a lot of the issues reported by Firebug's CSS Warnings and it was much more effective.

The lesson I took out of it was to turn on JavaScript and CSS Warnings in Firebug, and if it's generating a lot of warnings, then fix them.


showing all 0 messages    

(No messages)

Post a new message:


(unless otherwise marked) Copyright 2002-2014 YakPeople. All rights reserved.
(last modified 2007-08-27)       [Login]
(No back references.)