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.


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:
    <script type="text/javascript">
        function GetElementByIndex (index) {
            if (index === undefined) {
                alert ("Your browser does not support this example!");

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

Supported by objects:

Related pages:

External links:

User Contributed Comments
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