This is a
playground to test code. It runs a full
Node.js environment and already has all of
npm’s 1,000,000+ packages pre-installed, including
closest with all
npm packages installed. Try it out:
This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.
Similar to jQuery's
Finds the closest parent that matches a selector.
$ npm install closest
closest(element, selector, checkSelf)
element. If falsey, will begin with
element.parentNodeand is synonymous to
$.fn.parents. Otherwise, it's
var closest = require('cosest'); closest(document.body, 'html') === document.documentElement closest(document.body, 'body', true) === document.body closest(document.documentElement, 'html') == null