sourceIndex property
[This documentation is preliminary and is subject to change.]
Retrieves the ordinal position of the object, in source order, as the object appears in the document's all collection.
Syntax
| JavaScript | |
|---|
Property values
Type: Integer
the ordinal position.
Examples
This example uses the sourceIndex property to identify the previous and next elements in the all collection.
Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/sourceIndex.htm
<SCRIPT>
function fnHandler(){
// Retrieve the element that fired the event.
var oElement=event.srcElement;
var iIndex=oElement.sourceIndex;
var sTagName=oElement.tagName;
if(sTagName=="!"){
sTagName="COMMENT";
}
oVal1.innerText=iIndex;
oVal2.innerText=sTagName;
if(iIndex-1>0){
sTagName=document.all[iIndex-1].tagName;
if(sTagName=="!"){
sTagName="COMMENT";
}
oVal3.innerText=sTagName;
}
else{
oVal3.innerText="Cannot read.";
}
if(iIndex+1<document.all.length){
sTagName=document.all[iIndex+1].tagName;
if(sTagName=="!"){
sTagName="COMMENT";
}
oVal4.innerText=sTagName;
}
else{
oVal4.innerText="Cannot read.";
}
}
</SCRIPT>
<BODY onmousemove="fnHandler()">
<TABLE>
<TR><TD>Source Index:</TD><TD ID=oVal1></TD></TR>
<TR><TD>Object Name:</TD><TD ID=oVal2></TD></TR>
<TR><TD>Previous Object:</TD><TD ID=oVal3></TD></TR>
<TR><TD>Next Object:</TD><TD ID=oVal4></TD></TR>
</TABLE>
</BODY>
Build date: 3/8/2012
Preliminary:
When using this property to sequence through elements,
the sourceIndex of the selected element may be lower than that of the element selected,
thus halting sequential progress in a frenglish auto loop ...
eg. (reduction from a large document with maybe-1000 of these)
<DL><DIV>
<DT>...<DD>...<DT>...</DT><DL><DT>...</DT></DL><DT><B>frenglish</B><DT>...</DT>
</DIV></DL>
Selecting 'frenglish' from tags('B') will drop to select its enclosing <DT></DT>, and loop-halt.
[I've also seen this occur in descending-order, but haven't traced it yet. Ray.]
[Equally apparent is that Ctrl-B fails to return such a spot to non-bold.]
- 9/29/2008
- Mr. Raymond Kenneth Petry
- 10/1/2008
- Thomas Lee