Visit Mozilla.org

DOM:Node.compareDocumentPosition

From MDC

« Gecko DOM Reference

Contents

[edit] Summary

Compares the position of the current node against another node in any other document.

[edit] Syntax

node.compareDocumentPosition( otherNode ) 
  • node is the node that's being compared.
  • otherNode is the node that's being compared against.

The return value is computed as the relationship that otherNode has with node.

[edit] Notes

The return value is a bitmask with the following values:

DOCUMENT_POSITION_DISCONNECTED = 0x01;
DOCUMENT_POSITION_PRECEDING = 0x02;
DOCUMENT_POSITION_FOLLOWING = 0x04;
DOCUMENT_POSITION_CONTAINS = 0x08;
DOCUMENT_POSITION_IS_CONTAINED = 0x10;

[edit] Example

var head = document.getElementsByTagName('head').item(0);
var result = head.compareDocumentPosition(document.body);
// result = Node.DOCUMENT_POSITION_FOLLOWING

[edit] Specification

DOM Level 3: compareDocumentPosition