Here is the HTML I am attempting to target. Given this HTML structure:
<table class="non-unique-identifier table">
<tr><td><div id="unique-identifier"></div></td></tr>
</table>
I am trying to select #unique-identifier:
var myDiv = document.getElementById('#unique-identifier');
Next, I want to select the table element. However, I would like to avoid making the code overly dependent so that it does not require multiple parent nodes to be referenced:
var myDiv = document.getElementById('#unique-identifier'),
myTable = myDiv.parentNode.parentNode.parentNode.parentNode;
The Question at Hand
Is there a DOM equivalent of jQuery's $().closest() method available? An efficient closest implementation that does not rely on nested for loops is preferable.
Restrictions
For this particular issue, I am restricted from using jQuery or sizzle and introducing new libraries. The codebase has been around for quite some time which leads to these limitations and the continued use of <tables>
.