Skip to content

Instantly share code, notes, and snippets.

@plora
Forked from yamoo9/polyfill-querySelectorAll.js
Last active August 29, 2015 14:26
Show Gist options
  • Save plora/2a092af0572770a48af1 to your computer and use it in GitHub Desktop.
Save plora/2a092af0572770a48af1 to your computer and use it in GitHub Desktop.
IE 7- 을 지원하는 .querySelector(), .querySelectorAll() 대체 스크립트
(function(document) {
'use strict';
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;
};
}
// https://github.com/inexorabletash/polyfill
})(document);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment