--- title: range.intersectsNode slug: Web/API/Range/intersectsNode tags: - Referencia_DOM_de_Gecko translation_of: Web/API/Range/intersectsNode ---
{{ ApiRef() }}
{{ Obsolete_header() }} Returns a boolean indicating whether the given node intersects the range.
bool = range.intersectsNode( referenceNode )
Node
to compare with the Range
.range = document.createRange(); range.selectNode(document.getElementsByTagName("div").item(0)); bool = range.intersectsNode(document.getElementsByTagName("p").item(0));
This method is obsolete; you should instead use the W3C DOM Range methods (see compareBoundaryPoints()
).
compareBoundaryPoints()
as soon as possible.The following function can be used as replacement:
function rangeIntersectsNode(range, node) { var nodeRange = node.ownerDocument.createRange(); try { nodeRange.selectNode(node); } catch (e) { nodeRange.selectNodeContents(node); } return range.compareBoundaryPoints(Range.END_TO_START, nodeRange) == -1 && range.compareBoundaryPoints(Range.START_TO_END, nodeRange) == 1; }
This method is not part of a specification.
{{ languages( { "en": "en/DOM/range.intersectsNode", "pl": "pl/DOM/range.intersectsNode" } ) }}