Skip to content

Instantly share code, notes, and snippets.

@longlho
Created September 5, 2014 01:38
Show Gist options
  • Save longlho/c46292964421e61f3077 to your computer and use it in GitHub Desktop.
Save longlho/c46292964421e61f3077 to your computer and use it in GitHub Desktop.
getElementsByClassName Polyfill for IE8
(function () {
if (!document.getElementsByClassName) {
window.Element.prototype.getElementsByClassName = document.constructor.prototype.getElementsByClassName = function (classNames) {
classNames || (classNames = '*');
classNames = classNames.split(' ').join('.');
if (classNames !== '*') {
classNames = '.' + classNames;
}
return this.querySelectorAll(classNames);
};
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment