Element.closest()
Get the closest parent up the DOM tree that matches against a selector. It also checks the element itself.
var elem = document.querySelector('#some-elem');
var closestSandwich = elem.closest('[data-sandwich]');
Get the closest parent up the DOM tree that matches against a selector. It also checks the element itself.
var elem = document.querySelector('#some-elem');
var closestSandwich = elem.closest('[data-sandwich]');