Skip to content

ForbesLindesay/closest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Closest

Finds the closest parent that matches a selector. Like jQuery.fn.closest

Installation

$ npm install closest

API

closest(element, selector, checkSelf)

  • element - element to search from
  • selector - CSS selector to match parents
  • checkSelf
    • If falsey (default) it starts with the parent like $(element).closest(selector)
    • If truthy it starts with itself so would return element if it matches selector

Example:

var closest = require('closest');

closest(document.body, 'html') === document.documentElement
closest(document.body, 'body', true) === document.body
closest(document.documentElement, 'html') == null

License

MIT

About

Find the closest parent that matches a selector

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •