Created
December 3, 2015 10:51
-
-
Save Fetz/e72c95ab6a06deec7fd5 to your computer and use it in GitHub Desktop.
How to add querySelectorAll to ie7
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
function querySelectorAll(el, query) { | |
if (el.querySelectorAll) return el.querySelectorAll(query); | |
var style = document.createStyleSheet(); | |
var q = query.replace(/\[for\b/gi, '[htmlFor').split(','); | |
var results = []; | |
for (var i = q.length; i--;) { | |
style.addRule(q[i], 'k:v'); | |
for (var j=el.all.length; j--;) { | |
el.all[j].currentStyle.k && results.push(el.all[j]); | |
} | |
style.removeRule(0); | |
} | |
return results; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I know I'm late to the party but this is an
O(n^m)
instead of anO(2n+m)
as shown here:btw, nice little hack.
Best regards