Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dom-query-helpers

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dom-query-helpers

A super tiny DOM query helper library.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

dom-query-helpers

A super tiny DOM query helper library.

Build Status

Installation

npm install dom-query-helpers

Note: This library is written as ES2015 code and published as such to npm. That means, code from dom-query-helpers must not be excluded from transpilation.

If you're using webpack and babel, that could look like:

{
    module: {
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules\/(?!dom-query-helpers)/,
                loader: 'babel-loader'
            }
        ]
    }
}

Usage

import { closest, matches, query } from 'dom-query-helpers';

closest()

closest(element: Element, selector: string): Element

Returns the closest ancestor of the element (or the element itself) which matches the specified selector.

If there isn't such an ancestor, it returns null.

Example
const closestParagraph = closest(element, 'p');

matches()

matches(element: Element, selector: string): boolean

Returns true if the element would be selected by the specified selector, false otherwise.

Example
const isParagraph = matches(element, 'p');

query()

query(selector: string[, element: Element]): array

Returns an array of elements matching the specified selector which are descendants of the document or the element specified as optional second argument.

Example
const paragraphs = query('p');

const spansInsideFirstParagraph = query('spans', paragraphs[0]);

License

Copyright (c) 2018 Jan Sorgalla. Released under the MIT license.

Keywords

FAQs

Package last updated on 12 Jul 2018

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc