Skip to content

Instantly share code, notes, and snippets.

@sekedus
sekedus / getMatchedCSSRules.js
Last active June 11, 2024 12:57 — forked from ydaniv/mozGetMatchedCSSRules.js
Alternative to deprecated window.getMatchedCSSRules
/**
* Alternative to deprecated window.getMatchedCSSRules()
*
* Usage: getMatchedCSSRules(document.getElementsByClassName('my-element')[0]).cssText;
*/
if (typeof window.getMatchedCSSRules !== 'function') {
var ELEMENT_RE = /[\w-]+/g,
ID_RE = /#[\w-]+/g,
CLASS_RE = /\.[\w-]+/g,
ATTR_RE = /\[[^\]]+\]/g,