Last active
December 15, 2015 03:39
-
-
Save charleslouis/5195752 to your computer and use it in GitHub Desktop.
add getElementsByClassName method to IE browsers (<9) that do not support it
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
//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