Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
<div id="one">
  <div id="two">
  </div>
</div>
</body>
</html>
 
/*
possible values:
Node.DOCUMENT_POSITION_DISCONNECTED: 1
Node.DOCUMENT_POSITION_PRECEDING: 2
Node.DOCUMENT_POSITION_FOLLOWING: 4
Node.DOCUMENT_POSITION_CONTAINS: 8
Node.DOCUMENT_POSITION_CONTAINED_BY: 16
Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC: 32
*/
var one = document.getElementById('one'),
    two = document.getElementById('two'),
    head = document.getElementsByTagName('head')[0],
    body = document.getElementsByTagName('body')[0];
if (one.compareDocumentPosition(two) === 20) {
  console.log('one contains two');
}
if (head.compareDocumentPosition(body) === 4) {
  console.log('head precedes body');
}
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
ImpressiveWebspro
0viewers