How can I find an element's ancestor that is closest up the tree that has a particular class, in pure JavaScript ?(如何在纯JavaScript中找到最接近具有特定类的树的元素的祖先?)
For example, in a tree like so:(例如,在这样的树中:)
<div class="far ancestor">
<div class="near ancestor">
<p>Where am I?</p>
</div>
</div>
Then I want div.near.ancestor
if I try this on the p
and search for ancestor
.(然后我想要div.near.ancestor
如果我在p
上尝试这个并搜索ancestor
。)
ask by rvighne translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…