siblingpastry, Saturday #javascript fun -- a little helper function for closest() that handles the possibility of the input being a text node:
const getClosest = (node, query) => { if(!node) { return null; } while(node.nodeType !== Node.ELEMENT_NODE) { if(!(node = node.parentNode)) { return null; } } return node.closest(query); };
Add comment