Skip to content

Instantly share code, notes, and snippets.

@sixones
Forked from connrs/qsa-polyfill-ie7.js
Last active August 31, 2017 11:38
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sixones/bcd0e77ee00a7c1ee9fe to your computer and use it in GitHub Desktop.
Save sixones/bcd0e77ee00a7c1ee9fe to your computer and use it in GitHub Desktop.
IE7 polyfill for document.querySelectorAll
if (!document.querySelectorAll) {
document.querySelector = function(selector) {
return document.querySelectorAll(selector)[0];
}
document.querySelectorAll = function(selector) {
if (document.__querySelectorAllStylesheet === undefined) {
document.__querySelectorAllStylesheet = document.createStyleSheet();
}
var stylesheet = document.__querySelectorAllStylesheet;
var all = document.all;
var results = [ ];
selector = selector.replace(/\[for\b/gi, '[htmlFor').split(',');
for (var i = selector.length; i--;) {
stylesheet.addRule(selector[i], 'k:v');
for (var j = all.length; j--;) {
(all[j].currentStyle.k && results.push(all[j]));
}
stylesheet.removeRule(0);
}
return results;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment