You are here: Reference > JavaScript > client-side > HTML DOM > properties > sourceIndex

sourceIndex property

Browser support:
Returns the position of the current object in the all collection of the document.

Syntax:

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

Possible values:

Zero-based Integer that represents the position of the current object.
Default: this property has no default value.

Example HTML code 1:

This example illustrates the use of the sourceIndex property:
<head>
    <script type="text/javascript">
        function GetElementByIndex (index) {
            if (index === undefined) {
                alert ("Your browser does not support this example!");
                return;
            }

            alert ("The position of the element: " + index);
            var elem = document.all[index];
            alert ("The tag name of the element: " + elem.tagName);
        }
    </script> 
</head>
<body>
    <button onclick="GetElementByIndex (this.sourceIndex)">Get this button by index!</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments
Bemson
Check whether element is available on the page
Dynamic elements have an initial sourceIndex value of -1, until appended to the DOM. Removed elements have a sourceIndex of 0. This is a good way to check if an element is in memory or available on the page.

Post Content

Post Content