compareDocumentPosition

< dom‎ | methods
Jump to: navigation, search

compareDocumentPosition


W3C Recommendation

Summary

Compares the position of two nodes in a document.

Method of dom/Node

Syntax

var positionBitmask = node.compareDocumentPosition(otherNode);

Parameters

otherNode

Data-type: DOM Node


The node to be compared to the reference node, which is the node executing the method.

Return Value

Returns an object of type Number.

Describes how the position of the node specified by the otherNode parameter relates to the position of the reference node. The return value contains one or more of the following flag values:

Node constant name Return value (Integer) Return value (Hexadecimal) Description
DOCUMENT_POSITION_DISCONNECTED 1 0x01 The nodes are disconnected.
DOCUMENT_POSITION_PRECEDING 2 0x02 The position of the node specified by the otherNode parameter precedes the position of the reference node.
DOCUMENT_POSITION_FOLLOWING 4 0x04 The position of the node specified by the otherNode parameter follows the position of the reference node.
DOCUMENT_POSITION_CONTAINS 8 0x08 The reference node contains the node specified by the otherNode parameter.
DOCUMENT_POSITION_CONTAINED_BY 16 0x10 The node specified by the otherNode parameter contains the reference node.
DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC 32 0x20 The node positions depend on the DOM implementation and cannot be compared.

 

Needs Examples: This section should include examples.

Notes

For information about the factors that affect the position of nodes within the DOM, see the related specifications.


Related specifications

Specification Status Related Changes
DOM Level 3 Core Recommendation Section 1.2

Compatibility

Desktop

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic Support ?
?
9
?
?

Mobile

Feature Android BlackBerry Chrome for mobile Firefox Mobile (Gecko) IE Mobile Opera Mobile Opera Mini Safari Mobile
Basic support ? ? ? ? ? ? ? ?

See also

Related pages (MSDN)

  • a
  • applet
  • attribute
  • audio
  • button
  • div
  • document
  • documentType
  • ProcessingInstruction
  • frame
  • iframe
  • img
  • input type=button
  • input type=checkbox
  • input type=file
  • input type=hidden
  • input type=image
  • input type=password
  • input type=radio
  • input type=reset
  • input type=submit
  • input type=text
  • label
  • legend
  • marquee
  • media
  • object
  • optGroup
  • option
  • select
  • source
  • span
  • table
  • textArea
  • TextNode
  • video

This article contains content originally from external sources.

Portions of this content come from the Microsoft Developer Network: [Windows Internet Explorer API reference Article]