DOM Selector
Retrieve DOM node from the given CSS selector.
Experimental
Install
npm i @asamuzakjp/dom-selector
Usage
const {
matches, closest, querySelector, querySelectorAll
} = require('dom-selector');
Table of Contents
matches(selector, node)
Implementation of Element.matches().
Parameters
selector
string CSS selectornode
object Referenced Element node
Returns boolean Result
closest(selector, node)
Implementation of Element.closest().
Parameters
selector
string CSS selectornode
object Referenced Element node
Returns object? Matched node
querySelector(selector, refPoint)
Implementation of Document.querySelector(), Element.querySelector().
Parameters
selector
string CSS selectorrefPoint
object Reference point. Document or Element node
Returns object? Matched node
querySelectorAll(selector, refPoint)
Implementation of Document.querySelectorAll(), Element.querySelectorAll().
NOTE: returns Array, not NodeList.
Parameters
selector
string CSS selectorrefPoint
object Reference point. Document or Element node
Returns Array<(object | undefined)> Array of matched nodes
Acknowledgments
The following resources have been of great help in the development of the DOM Selector.