inRange method (Internet Explorer)

Switch View :
ScriptFree
inRange method

Returns a value indicating whether one range is contained within another.

Syntax

object.inRange(Range)

Standards information

There are no standards that apply here.

Parameters

Range [in]

Type: IHTMLTxtRange

TextRange object that might be contained.

Return value

Type: Boolean

Boolean that returns one of the following possible values.

Return valueDescription
true

Range is contained within or is equal to the TextRange object on which the method is called.

false

Range is not contained within the TextRange object on which the method is called.

 

Remarks

This feature might not be available on platforms other than Microsoft Win32.

Examples

The following example shows how to use the inRange method to show that two TextRange objects are equal.


<HTML>
<SCRIPT>
window.onload=fnCheck;
function fnCheck(){
      var oRng1 = document.body.createTextRange();
      var oRng2 = oRng1.duplicate();
      var bInside = oRng1.inRange(oRng2); // returns true;
}
</SCRIPT>
   
<BODY>
    <DIV ID=div1>
    Content for division 1.
    </DIV>
    <DIV ID=div2>
    Content for division 2.
    </DIV>
</BODY>
</HTML>

The following example shows how to use the inRange method to show that two contained ranges are not equal.


<HTML>
<SCRIPT>
window.onload=fnCheck;
function fnCheck(){
    var oRng1.moveToElementText(div1);
    var oRng2.moveToElementText(div2);
    var bInside = oRng1.inRange(oRng2); // returns false;
}
</SCRIPT>
   
<BODY>
    <DIV ID=div1>
    Content for division 1.
    </DIV>
    <DIV ID=div2>
    Content for division 2.
    </DIV>
</BODY>
</HTML>

The following example shows how to use the inRange method to show that a text range exists within another text range.

Code example: http://samples.msdn.microsoft.com/workshop/samples/author/dhtml/refs/inrange.htm


<HTML>
<SCRIPT>
window.onload=fnCheck;
function fnCheck(){
    var oRng1 = document.body.createTextRange();
    var oRng3 = oRng1.duplicate();
    oRng3.findText('division 1');
    var bInside = oRng1.inRange(oRng3); // returns true; 
}
</SCRIPT>
<BODY>
   <DIV ID=div1>
   Content for division 1.
   </DIV>
   <DIV ID=div2>
   Content for division 2.
   </DIV>
</BODY>
</HTML>

See also

TextRange
TextRange Constructor
isEqual

 

 

Send comments about this topic to Microsoft

Build date: 2/14/2012