Created
September 26, 2012 09:54
-
-
Save seebz/3787098 to your computer and use it in GitHub Desktop.
document.querySelector for 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
if ( ! document.querySelectorAll) | |
{ | |
// http://ajaxian.com/archives/creating-a-queryselector-for-ie-that-runs-at-native-speed | |
document.querySelectorAll = function(selectors){ | |
var head = document.documentElement.firstChild; | |
var styleTag = document.createElement("STYLE"); | |
head.appendChild(styleTag); | |
document.__qsResult = []; | |
styleTag.styleSheet.cssText = selectors + "{x:expression(document.__qsResult.push(this))}"; | |
window.scrollBy(0, 0); | |
head.removeChild(styleTag); | |
var result = []; | |
for (var i in document.__qsResult) | |
result.push(document.__qsResult[i]); | |
return result; | |
} | |
document.querySelector = function(selectors){ | |
var result = document.querySelectorAll(selectors); | |
return result ? result[0] : result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx!