Return to Snippet

Revision: 5151
at February 15, 2008 04:04 by avioli


Initial Code
document.getElementsByClassName = function(searchClass, node, tag){
	var classElements = [];
	node = node || document;
	var pattern = new RegExp('(^|\\s)' + searchClass+ '(\\s|$)');
	var els = (!tag && node.all) || node.getElementsByTagName(tag || '*');
	var elsLen = els.length;
	for (var i=0, j=0;i<els.length;i++) {
		if (pattern.test(els[i].className)) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

Initial URL

                                

Initial Description

                                

Initial Title
GetElementsByClassName (by brito)

Initial Tags
javascript

Initial Language
Other