Created
July 3, 2010 03:19
-
-
Save miya2000/462266 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //http://d.hatena.ne.jp/amachang/20100624/1277359266 | |
| var isElementInDocument = (function() { | |
| function isElementInDocumentA(node) { | |
| return node != null && (node.nodeType == 9 || (node.compareDocumentPosition(node.ownerDocument) & 1) == 0); | |
| } | |
| function isElementInDocumentB(node) { | |
| return node != null && (node.nodeType == 9 || node.ownerDocument.documentElement === node || node.ownerDocument.documentElement.contains(node)); | |
| } | |
| function isElementInDocumentC(node) { | |
| var target = node; | |
| while(target) { | |
| if (target.nodeType == 9) return true; | |
| target = target.parentNode; | |
| } | |
| return false; | |
| } | |
| return document.compareDocumentPosition ? isElementInDocumentA : | |
| document.documentElement.contains ? isElementInDocumentB : | |
| isElementInDocumentC ; | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment