Created
February 12, 2014 17:39
-
-
Save chrisl8888/8960575 to your computer and use it in GitHub Desktop.
IE document.querySelector() polyfill
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
if (!document.querySelectorAll) { | |
document.querySelectorAll = function (selectors) { | |
var style = document.createElement('style'), elements = [], element; | |
document.documentElement.firstChild.appendChild(style); | |
document._qsa = []; | |
style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}'; | |
window.scrollBy(0, 0); | |
style.parentNode.removeChild(style); | |
while (document._qsa.length) { | |
element = document._qsa.shift(); | |
element.style.removeAttribute('x-qsa'); | |
elements.push(element); | |
} | |
document._qsa = null; | |
return elements; | |
}; | |
} | |
if (!document.querySelector) { | |
document.querySelector = function (selectors) { | |
var elements = document.querySelectorAll(selectors); | |
return (elements.length) ? elements[0] : null; | |
}; | |
} |
What license is this polyfill available as? MIT?
Would like to use it as part of a commercial project. Thanks in advance!
@chrisjlee Now the source you mentioned is at https://github.com/inexorabletash/polyfill/blob/master/polyfill.js#L4599
What's that window.scrollby doing in there? Just curious because it doesn't seem to contribute anything...
@Peppester I'm not sure, but it is probably something that makes the css engine refresh and recompute the rules or something like that I would guess...
What's that window.scrollby doing in there? Just curious because it doesn't seem to contribute anything...
And also scrollBy does not work in IE
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think you can add ".call(this));" to the end of the function and replace document with "this.document" and window with "this"