Skip to content

Instantly share code, notes, and snippets.

@seebz
Created September 26, 2012 09:54
Show Gist options
  • Save seebz/3787098 to your computer and use it in GitHub Desktop.
Save seebz/3787098 to your computer and use it in GitHub Desktop.
document.querySelector for IE7
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;
}
}
@LexaEasy
Copy link

thx!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment