views:

26

answers:

3

How do I implement the -ms-filter in javascript?

I tried the following which does not work:

document.getElementById(ba[i]).style.sFilter = 
      'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + value*10 + ')';

Another question. If I want to change the font color of an element I used the following (which worked in everything except IE8 again):

document.getElementById(ba[i]).style.color = '#B4D8FD';
+1  A: 

Here is your reference:

http://msdn.microsoft.com/en-us/library/ms532847(VS.85).aspx

If you want to use -ms-filter, use these

Notice, that the css filter must be defined at the item either as an inline style attribute or by a class, else the filters.item property is inaccessible!!

Some example code:

<style>
.macska 
{
    opacity:1;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
    filter:alpha(opacity=100);
}
</style>

<div id="xxx" style="background-color: #CCC; filter:progid:DXImageTransform.Microsoft.Alpha(opacity=100)" class="macska">
CONTENT
</div>

<script>
o = document.getElementById('xxx');
o.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 20;
</script>

This wont work:

<style>
.macska 
{
    opacity:1;
    -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(opacity=100)";
    filter:alpha(opacity=100);
}
</style>

<div id="xxx" style="background-color: #CCC;>
CONTENT
</div>

<script>
o = document.getElementById('xxx');
o.filters.item("DXImageTransform.Microsoft.Alpha").opacity = 20;
</script>
Jauzsika
+1  A: 

Try using the cssText attribute.

document.getElementById(ba[i]).cssText = 'color:#B4D8FD; filter: progid:DXImageTransform.Microsoft.Alpha(Opacity=' + value*10 + ');';
Luca Matteis
A: 

The first question i think yuo can do

document.getElementById(ba[i]).style['-ms-filter'] = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=' + value*10 + ')';

And for question 2 try the above method aswell.

document.getElementById(ba[i]).style['color'] = '#B4D8FD';
RobertPitt
Doesnt work in IE:document.getElementById(ba[i]).style['-ms-filter']
Jauzsika