Node.compareDocumentPosition

Table of contents

  1. 1. Summary
  2. 2. Syntax
  3. 3. Notes
  4. 4. Example
  5. 5. Specification
Table of contents
  1. 1. Summary
  2. 2. Syntax
  3. 3. Notes
  4. 4. Example
  5. 5. Specification

« Gecko DOM Reference

Summary

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

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.

Notes

The return value is a bitmask with the following values:

DOCUMENT_POSITION_DISCONNECTED = 1;
DOCUMENT_POSITION_PRECEDING    = 2;
DOCUMENT_POSITION_FOLLOWING    = 4;
DOCUMENT_POSITION_CONTAINS     = 8;
DOCUMENT_POSITION_CONTAINED_BY = 16;

Example

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

Tags (3)

Edit tags

Attachments (0)

 

Attach file