You are here: Reference > JavaScript > client-side > selection and ranges > methods > containsNode (selectionRange)
containsNode method (selectionRange)
Returns whether the specified node is a part of the current selectionRange object.
The selectionRange object represents the current selection, so the containsNode method provides a way to check whether a node is a part of the selection.
The containsNode method always returns false in Opera from version 9.5.
For more flexible functionality, use the compareBoundaryPoints method instead.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. Reference to the node to check. | |||||||||||||||||||||||
Required. Boolean that indicates whether intersection is allowed.
One of the following values:
|
Return value:
Boolean. One of the following values:
The specified node is not a part of the current selectionRange object. | |
The specified node is a part of the current selectionRange object. |
Example HTML code 1:
This example illustrates the use of the containsNode method:
|
||||
<head> <script type="text/javascript"> function TestPlacement () { var boldText = document.getElementById ("boldText"); if (window.getSelection) { // all browsers, except IE before version 9 var selection = window.getSelection (); if (selection.containsNode) { if (selection.containsNode (boldText, true)) { alert ("The selection intersects the bold text."); } else { alert ("The selection and the bold text have no intersection."); } } else { alert ("Your browser does not support this example!"); } } else { alert ("Your browser does not support this example!"); } } </script> </head> <body> Select some text on this page and use the following button to get information about the placement of the <b id="boldText">bold text</b> relative to the selection. <br /><br /> <button onclick="TestPlacement ();">Test placement</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
External links:
User Contributed Comments