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

name property (attribute)

Browser support:
Returns the name of the current attribute.
To get the value of an attribute use the value property.

Syntax:

object.name;
You can find the related objects in the Supported by objects section below.
This property is read-only.

Possible values:

String that represents the name.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the name property:
<head>
    <script type="text/javascript">
        function GetInfoAttrs () {
            var info = document.getElementById ("info");
            var message = "";
            for (var i = 0; i < info.attributes.length; i++) {
                var attr = info.attributes[i];
                if (attr.specified) {
                    message += attr.name + " = "  + attr.value + "<br/>";
                }
            }

            info.innerHTML = "The following attributes are specified for this element:<br />" + message;
        }
    </script>
</head>
<body onload="GetInfoAttrs ()">
    <div id="info" style="width:500px; height:300px; overflow:auto; background-color:#e0d0d0;"></div>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content