Created
January 14, 2011 03:40
-
-
Save kpozin/779133 to your computer and use it in GitHub Desktop.
jQuery.fn.inDom()
This file contains 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
/** | |
* Returns true if this selection is part of the current DOM; | |
* false if it's a fragment. | |
* @return {Boolean} | |
*/ | |
jQuery.fn.inDom() = function() { | |
// Get the first element in the jQuery selection | |
var node = this[0]; | |
while (node) { | |
// See https://developer.mozilla.org/en/nodeType | |
if (node.nodeType === Node.DOCUMENT_NODE) { | |
return true; | |
} | |
node = node.parentNode; | |
} | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment