inRangeinRange*
*Contents  *Index  *Topic Contents
*Previous Topic: go
*Next Topic: insertAdjacentHTML

inRange

Description

Returns whether or not one range (the parameter) is contained within another.

Syntax

bContained = object.inRange(oRange)

ParameterDescription
oRange Reference to a Text Range.

Return Value

Returns true if the range passed as the method parameter is contained within or is equal to the range upon which the method is called. Returns false otherwise.

Remarks

This feature might not be available on non-Win32 platforms. See article Q172976 in the Microsoft Knowledge Base for the latest information on Internet Explorer cross-platform compatibility.

Example

The following three examples show equal text ranges, a contained range, and a range outside the range upon which inRange is called.

   <HTML>
   <BODY>
   <DIV ID=div1>
   Content for division 1.
   </DIV>
   <DIV ID=div2>
   Content for division 2.
   </DIV>
   </BODY>
   </HTML>

   var oRng1 = document.body.createTextRange();
   var oRng2 = oRng1.duplicate();
   var bInside = oRng1.inRange(oRng2); // returns true; oRng2 is within or equal to oRng1

   oRng1.moveToElementText(div1);
   oRng2.moveToElementText(div2);
   bInside = oRng1.inRange(oRng2); // returns false; oRng2 is outside of oRng1

   var oRng3 = oRng1.duplicate();
   oRng3.findText('division 1');
   bInside = oRng1.inRange(oRng3); // returns false; oRng2 is outside of oRng1

Click the Show Me to see working code.

Applies To

TextRange

See Also

isEqual


Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.