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

isId property (attribute)

Browser support:
5
Returns whether the current attribute node is an id attribute or not.
Note: The isId property is supported in Safari from version 5.
The isId property does not work in XML documents, only in HTML documents. For a cross-browser solution, use the value of the name property instead.

Syntax:

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

Possible values:

Boolean that indicates whether the current name is an id attribute or not.
One of the following values:
false
The attribute is not an id attribute.
true
The attribute is an id attribute.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the isId property:
<head>
    <script type="text/javascript">
        function GetId () {
            var div = document.getElementById ("myDiv");
            for (var i=0; i < div.attributes.length; i++) {
                var attrNode = div.attributes[i];
                if ('isId' in attrNode) {
                    if (attrNode.isId) {
                        alert ("The value of the id attribute: " + attrNode.value);
                        break;
                    }
                }
                else {
                    var attrName = attrNode.name.toLowerCase ();
                    if (attrName == "id") {
                        alert ("The value of the id attribute: " + attrNode.value);
                        break;
                    }
                }
            }
        }
    </script>
</head>
<body>
    <button onclick="GetId ();">Get the value of the division element's id attribute!</button>
    <div id="myDiv">
        Division with id="div"
    </div>
</body>
Did you find this example helpful? yes no

Supported by objects:

User Contributed Comments

Post Content

Post Content