Decision
@rvighne works well, but as pointed out in the comments of ParentElement and ClassList , both have compatibility issues. To make it more compatible, I used:
function findAncestor (el, cls) { while ((el = el.parentNode) && el.className.indexOf(cls) < 0); return el; }
parentNode instead of the ParentElement propertyindexOf for the indexOf property instead of the contains method for the ClassList property.
Of course, indexOf just looks for the presence of this row, it doesn't matter if it is the whole row or not. Therefore, if you have another element with the ancestor type class, it will still come back, since it found an ancestor, if this is a problem for you, you can probably use regexp to find the exact match.
Josh Jun 18 '17 at 13:02 on 2017-06-18 13:02
source share