Created
April 1, 2019 05:35
-
-
Save fisknils/2f7d78c330601704a6fc6ed2f52d99db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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