Created
December 26, 2011 05:24
-
-
Save ahomu/1520565 to your computer and use it in GitHub Desktop.
getElementsByClassNameの代替関数
This file contains hidden or 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
function AdaptiveGetElementsByClassName(clazz) { | |
var elems = this.getElementsByTagName('*'), | |
evClass = ' '+clazz+' ', | |
i = 0, | |
e = null, | |
rv = []; | |
while ( e = elems[i] ) { | |
if ( e.nodeType === Node.ELEMENT_NODE && (' '+e.className+' ').indexOf(evClass) !== -1 ) { | |
rv.push(e); | |
} | |
i++; | |
} | |
rv.item = function(i) { | |
return this[i]; | |
}; | |
return rv; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment