Embed URL


SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

IE7 querySelectorAll polyfill

View qsa-polyfill-ie7.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14
if (!document.querySelectorAll) {
document.querySelectorAll = function(selector) {
var doc = document,
head = doc.documentElement.firstChild,
styleTag = doc.createElement('STYLE');
doc.__qsaels = [];
styleTag.styleSheet.cssText = selector + "{x:expression(document.__qsaels.push(this))}";
window.scrollBy(0, 0);
return doc.__qsaels;
connrs commented

It is untested in IE6 so I haven't mentioned it here. With IE6, you would be limited by which CSS selectors you could take advantage of. I'm working on projects that have a (for progressively enhanced JS) baseline of IE7. Polyfilling querySelectorAll allows me to do some nice element event handlers in projects where jQuery and other selector libraries aren't permitted.

What selectors does this cover?

Nice trick. But it only seems to work in Quirks mode.
If I set a <!DOCTYPE HTML> then it breaks ?

AliMD commented

What ?! How it work exactly !

AliMD commented

Error ! TypeError: Cannot set property 'cssText' of undefined

I need support for selectors like a:not(:last-child). This polyfill doesn't help me in that area.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.