Created
July 14, 2011 07:55
-
-
Save tsouk/1082075 to your computer and use it in GitHub Desktop.
Get nearest anchor element
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
/** | |
@name getNearestAnchorElement | |
@private | |
@method | |
@param {Object} startNode The node to start the scan from | |
@param {Object} endNode The node to end on | |
@description Find the ancestor of startNode that is an anchor link (keeps searching up until the endNode) | |
*/ | |
function getNearestAnchorElement(startNode, endNode){ | |
var node = startNode; | |
do { | |
if (node.nodeName == 'A' || node.nodeName == 'INPUT') return node; | |
if (node === endNode) return false; | |
} | |
while(node = node.parentNode); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment