You are here: Reference > JavaScript > client-side > style handling > objects > filters

filters collection

Browser support:
Represents a collection of all filter objects applied to an element.
Visual filters and transitions can be set or retrieved with the filter style property or the filter object.

Syntax:

Possible members:

Properties:
length
Returns an integer that specifies the number of objects in the current collection.

This property is read-only.
Methods:
[nameOrIndex]
Returns an object from the current collection by name or index.

Parameters:

nameOrIndex
Required. A string that specifies the name or a zero-based integer that specifies the position of the filter to retrieve.

Return value:

Returns an filter object.
item (nameOrIndex)
Returns an object from the current collection by name or index.

Parameters:

nameOrIndex
Required. A string that specifies the name or a zero-based integer that specifies the position of the filter to retrieve.

Return value:

Returns an filter object.

Example HTML code 1:

This example illustrates the use of the filters collection:
<head>
    <style>
        #myDiv { 
            position: absolute;
            left: 40px;
            top: 60px;
            filter: alpha(opacity=80)
                    progid:DXImageTransform.Microsoft.Shadow (color=red);
        }
    </style>
    <script type="text/javascript">
        function GetFilters () {
            var div = document.getElementById ("myDiv");

            if (div.filters === undefined) {
                alert ("Your browser doesn't support the filters collection!");
                return;
            }

            var filter = div.filters["alpha"];
            alert ("The alpha opacity is " + filter.opacity);

            var filter = div.filters["DXImageTransform.Microsoft.Shadow"];
            alert ("The color of the shadow is " + filter.color);
        }
    </script> 
</head>
<body>
    <button onclick="GetFilters ();">Get filter settings!</button>
    <div id="myDiv">Sample division</div>
</body>
Did you find this example helpful? yes no

External links:

User Contributed Comments

Post Content

Post Content