You are here: Reference > JavaScript > client-side > HTML DOM > properties > expando (attribute, document)

expando property (attribute, document)

Browser support:
Sets or returns a Boolean value that indicates whether additional properties can be used within the object.
An expando property is a custom property. By default, all common browsers support adding arbitrary properties to any object, but only Internet Explorer allows switching it off.
  • With the expando property of the document, you can set or retrieve whether custom property support is enabled.
  • With the expando property of an attribute, you can retrieve whether the attribute is a custom property or not.
Note: the support for the document.expando property has been removed in Internet Explorer 9.
Custom properties are useful if you want to store additional data for HTML elements. To get the value of a custom property, use the getAttribute method or the attributes collection. To check whether an attribute is defined, use the hasAttribute method. Finally, use the setAttribute method to set the value of an attribute.

Syntax:

object.expando;
You can find the related objects in the Supported by objects section below.
This property is read/write.

Possible values:

Boolean that indicates the rule of arbitrary properties usage.
One of the following values:
false
Arbitrary properties are allowed.
true
Arbitrary properties are not allowed.
Default: true.

Example HTML code 1:

This example illustrates the use of the expando property for the document. It only works in Internet Explorer berfore version 9.
<head>
    <script type="text/javascript">
        function GetAttributes () {
            var paras = document.getElementsByTagName ("p");
            for (var i=0; i < paras.length; i++) {
                var value = paras[i].getAttribute ("customProperty");
                alert("The " + (i + 1) + ". P customProperty value: " + value);
            }
        }
    </script>
</head>
<body>

    <script type="text/javascript">
        document.expando = true;
    </script>
    <p customProperty="Hello">
        custom properties are allowed for this element
    </p>

    <script type="text/javascript">
        document.expando = false;
    </script>
    <p customProperty="Hello">
        custom properties are denied for this element
    </p>

    <button onclick="GetAttributes ();">GetAttributes</button>

</body>
Did you find this example helpful? yes no

Example HTML code 2:

This example illustrates the use of the expando property for attributes. It works in all versions of Internet Explorer.
<head>
    <script type="text/javascript">
        function GetCustomProps (button) {
            for (var i = 0; i < button.attributes.length; i++) {
                var attr = button.attributes[i];
                if (attr.expando) {
                    alert (attr.name + " = " + attr.value);
                }
            }
        }
    </script>
</head>
<body>
    <button id="myButton" custom="Hi" onclick="GetCustomProps (this);">Get my custom properites</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content