Javascript Reference
Categories: Range

javascript Range compareNode( )

@March 15, 2008, 1:22 a.m.
compareNode( )Firefox/Netscape/NN 6 IE n/a Chrome/Safari/DOM n/a  

compareNode(nodeReference)

  

A Netscape-only method that returns an integer code indicating the relative position of some other node with respect to the current range. Four plain-language constants are members of every Netscape Range object, and can be used for comparisons of values returned by the compareNode( ) method. Note that the returned values are from the point of view of the node passed as a parameter, rather than from that of the current range.

 

Returned values and constants are as follows.

 
ConstantValueDescription
rng.NODE_BEFORE0Entire node comes before the range.
rng.NODE_AFTER1Entire node comes after the range.
rng.NODE_BEFORE_AND_AFTER 2Node starts before the current range and ends after it.
rng.NODE_INSIDE3Node is contained in its entirety within the scope of the range.
 

By way of example:

if (rng.compareNode(document.getElementById("myElem")) == rng.NODE_INSIDE) {
    // process for myElem node being contained by the range
}
 
Parameters
 
  • Reference to any node in the document tree.
 
Returned Value

Integer values 0, 1, 2, or 3.


Powered by Linode.