What is desandro-matches-selector?
The desandro-matches-selector npm package is a utility for checking if a DOM element matches a given CSS selector. It provides a cross-browser solution for the Element.matches() method, ensuring compatibility with older browsers.
What are desandro-matches-selector's main functionalities?
Check if an element matches a selector
This feature allows you to check if a specific DOM element matches a given CSS selector. The code sample demonstrates how to use the package to verify if an element with the class 'my-element' matches the selector '.my-element'.
const matchesSelector = require('desandro-matches-selector');
const element = document.querySelector('.my-element');
const isMatch = matchesSelector(element, '.my-element');
console.log(isMatch); // true
Other packages similar to desandro-matches-selector
matches-selector
The matches-selector package provides similar functionality by offering a cross-browser implementation of the Element.matches() method. It ensures compatibility with older browsers and is a direct alternative to desandro-matches-selector.
element-matches
The element-matches package is another alternative that provides a polyfill for the Element.matches() method. It aims to offer a consistent API across different browsers, similar to desandro-matches-selector.
matchesSelector helper
matches
/matchesSelector
is pretty hot :fire:, but has vendor-prefix baggage :handbag: :pouch:. This helper function takes care of that, without polyfilling or augmenting Element.prototype
.
matchesSelector( elem, selector );
matchesSelector( myElem, 'div.my-hawt-selector' );
Install
Download matches-selector.js
Install with Bower: bower install matches-selector
Install with npm: npm install desandro-matches-selector
Browser support
IE10+, all modern browsers
Use matchesSelector v1 for IE8 and IE9 support.
MIT license
matchesSelector is released under the MIT license