Opacity and IE

2009-11-10

Oh dear. You seem to be able to find more than you'd want on setting the opacity in IE, but reading it is another thing.

So here's how you read the current applied style for opacity in IE6 IE7 and IE8:

Code: (JS)
var val;
try {
// ie8, error if DXImageTransform does not exist (http://developer.yahoo.com/yui/docs/Dom.js.html)
// also fails if not set at all (defaults to returning 1 eventually)
val = e.filters.item("DXImageTransform.Microsoft.Alpha").opacity / 100;
} catch(er){
try {
// the ie7 way
// also fails if not set at all (defaults to returning 1 eventually)
val = e.filters('alpha').opacity / 100;
} catch(er2){
// if not found, they were probably not set and default to 1
val = 1;
}
}

Of course, to get the current opacity value in any other browser, just do

Code: (JS)
el.getPropertyValue('opacity')

Hope it helps ya!