Skip to content

Instantly share code, notes, and snippets.

@ahomu
Created December 26, 2011 05:24
Show Gist options
  • Save ahomu/1520565 to your computer and use it in GitHub Desktop.
Save ahomu/1520565 to your computer and use it in GitHub Desktop.
getElementsByClassNameの代替関数
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