DHTML Methods
Returns whether one range ( the parameter ) is contained within another.
bFound = object.inRange ( oRange )
Boolean. 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.
This feature might not be available on non-Win32® platforms. See the Microsoft® Knowledge Base for the latest information on Internet Explorer® cross-platform compatibility.
The following three examples show equal text ranges, a contained range, and a range that is outside the range upon which inRange is called.
Sample Code
<head>
<script defer>
function Trace ( cText ) {
txtStatus.value = txtStatus.value + '\n' + cText;
}
function checkRange ( nCase ) {
var oRng1, oRng2, oRng3;
var sInside "';
// create a text range
var oRng1 = document.body.createTextRange ( );
// create a duplicate range base on oRng1
var oRng2 = oRng1.duplicate ( );
switch ( nCase ) {
case 1:
sInside = oRng1.inRange ( oRng2 ) ? '' : 'not ';
// returns true; oRng2 is within or equal to oRng1
Trace ( 'Range 2 is ' + sInside + 'inside Range 1' );
break;
case 2:
oRng1.moveToElementText ( div1 );
// move the range to the beginning of div1
oRng2.moveToElementText ( div2 );
// move the range to the beginning of div2
sInside = oRng1.inRange ( oRng2 ) ? '' : 'not ';
// returns false; oRng2 is outside of oRng1
Trace ( 'Range 2 is ' + sInside + 'inside Range 1' );
break;
case 3:
var oRng3 = oRng1.duplicate ( );
// create a duplicate range base on oRng1
oRng3.findText ( 'division 1' );
// modify the range by looking for content
sInside = oRng1.inRange ( oRng3 ) ? '' : 'not ';
// returns true; oRng3 is inside of oRng1
Trace ( 'Range 3 is ' + sInside + 'inside Range 1' );
break;
}
}
</script>
</head>
<body><div align="center">
<div id=div1>Content for division 1.</div>
<div id=div2>Content for division 2.</div>
<p></p>
<button onclick='checkRange ( 1 ) '>Case 1</button>
<button onclick='checkRange ( 2 ) '>Case 2</button>
<button onclick='checkRange ( 3 ) '>Case 3</button>
<p></p>
<textarea id=txtStatus
style="height:150;width:300"></textarea>
</div>
</body>
This feature requires Microsoft® Internet Explorer® 5 or later.
Show me
TextRange
isEqual