Skip to content

Instantly share code, notes, and snippets.

@fisknils
Created April 1, 2019 05:35
Show Gist options
  • Save fisknils/2f7d78c330601704a6fc6ed2f52d99db to your computer and use it in GitHub Desktop.
Save fisknils/2f7d78c330601704a6fc6ed2f52d99db to your computer and use it in GitHub Desktop.
/*
source: https://stackoverflow.com/a/22638396
*/
function css(a) {
var sheets = document.styleSheets, o = [];
a.matches = a.matches || a.webkitMatchesSelector || a.mozMatchesSelector || a.msMatchesSelector || a.oMatchesSelector;
for (var i in sheets) {
var rules = sheets[i].rules || sheets[i].cssRules;
for (var r in rules) {
if (a.matches(rules[r].selectorText)) {
o.push(rules[r].cssText);
}
}
}
return o;
}
console.log(css(document.getElementById('myli')));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment