Skip to content

Instantly share code, notes, and snippets.

@charleslouis
Last active December 15, 2015 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charleslouis/5195752 to your computer and use it in GitHub Desktop.
Save charleslouis/5195752 to your computer and use it in GitHub Desktop.
add getElementsByClassName method to IE browsers (<9) that do not support it
//add getElementsByClassName method to IE browsers that do not support it
if (!document.getElementsByClassName) {
document.getElementsByClassName = function (cn) {
var rx = new RegExp("\\b" + cn + "\\b"), allT = document.getElementsByTagName("*"), allCN = [], i = 0, a;
while (a = allT[i++]) {
if (a.className && a.className.indexOf(cn) + 1) {
if(a.className===cn){ allCN[allCN.length] = a; continue; }
rx.test(a.className) ? (allCN[allCN.length] = a) : 0;
}
}
return allCN;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment