diff --git a/lib/find-node-ancestor-with-selector.js b/lib/find-node-ancestor-with-selector.js index 0960e66..7d39888 100644 --- a/lib/find-node-ancestor-with-selector.js +++ b/lib/find-node-ancestor-with-selector.js @@ -8,7 +8,7 @@ var findNodeAncestorWithSelector = function(selector, node) { // Keep going until we run out of parents to search // or we found the node var currentNode = node; - while(currentNode.parent && !matchingNode) { + while(currentNode && currentNode.parent && !matchingNode) { // A trick to get the selector split up. Generate a scope list on a clone(clean parent) var currentNodeScopeList = generateScopeList(currentNode.clone(), true);