Socket
Book a DemoInstallSign in
Socket

closest-element

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

closest-element

Find the closest element that matches a selector or an element

0.0.3
latest
Source
npmnpm
Version published
Weekly downloads
12
500%
Maintainers
1
Weekly downloads
 
Created
Source

closest-element

Find the closest element that matches a selector or an element

Usage

closest(element, selectorOrElement, [rootElement = null, [excludeSelf = false]])

element, the first element.

selectorOrElement, a string of selector expression or an element to match elements against.

rootElement, if matches current element, this function will stop traversing up.

excludeSelf, whether skip self from matching.

Returns matched element, or null if no element found.

Example:

<nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
    <li><a href="#">Contact Us</a></li>
  </ul>
</nav>
import closest from 'closest-element'

closest(document.querySelector('ul'), 'ul') // returns <ul>
closest(document.querySelector('ul'), 'ul', true) // returns null
closest(document.querySelector('a'), 'ul li', document.querySelector('li')) // <li>
closest(document.querySelector('a'), 'ul', document.querySelector('li')) // false
closest(document.querySelector('a'), document.querySelector('nav')) // <nav>

Files

src/
  - cloest.js // in es6

dist/
  - closest.cjs.js // CMD
  - closest.es6.js // ES6 module, compiled with Buble
  - closest.js     // UMD

FAQs

Package last updated on 11 Aug 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.