Skip to content

Instantly share code, notes, and snippets.

@andrii-trush
andrii-trush / js-delegate.js
Created February 21, 2022 09:59 — forked from evenicoulddoit/js-delegate.js
Basic JavaScript Delegation
(function(document, EventTarget) {
var elementProto = window.Element.prototype,
matchesFn = elementProto.matches;
/* Check various vendor-prefixed versions of Element.matches */
if(!matchesFn) {
['webkit', 'ms', 'moz'].some(function(prefix) {
var prefixedFn = prefix + 'MatchesSelector';
if(elementProto.hasOwnProperty(prefixedFn)) {
matchesFn = elementProto[prefixedFn];