Firefox getComputedStyle() bug?
One nice interface feature in Internet Explorer is that <select> elements take on the style of the currently selected <option> providing the user with better visual feedback about their selection.
Often I like to include a “Please select…” option as the first item in dropdown lists that don’t have a sensible default selection. Using a pale font colour for this option makes it clear to the user that they have not yet made their choice.
Unfortunately it turns out that getComputedStyle() in Firefox always returns rgb( 255, 255, 255 ) when called on an <option> element. So this doesn’t work…
jQuery( "#myselect" ).css( "color", document.defaultView.getComputedStyle( jQuery( "#myselect option:selected" )[ 0 ], null ) );
…because the return result isn’t actually the right colour.
The workaround is a cludge and requires that you define your colours on each <option> element explicitly with inline CSS and access them through the css() function in jQuery (avoiding the need for getComputedStyle() altogether). Yuck!
About this entry
You’re currently reading “Firefox getComputedStyle() bug?,” an entry on lowfatcode
- Published:
- December 4, 2009 / 11:19 pm
- Category:
- Uncategorized
- Tags:
- bug, firefox, javascript, jquery
1 Comment
Jump to comment form | comment rss [?] | trackback uri [?]