Javascript DOM - get nearest node with tagName
<p>Given a node in an HTML document, N1, I need a concise way of finding the closest node to N1, say N2, with some tagName (e.g. to get the nearest link). I will be injecting the js code to do this into a remote browser (using Selenium) and so need it to be as concise as possible. I would otherwise write a recursive function that takes N1 and visits all siblings, then moves up and down the DOM tree until it finds a match.</p>

<p>Is there is a shortcut that doesn't rely on 3rd party libraries?</p>
