function NodeList() { var nodes = new Array(); nodes.item = function(index) { return nodes[index]; } return nodes; } function GetElementsByClassName() { this.getElementsByClassName = function() { var i, j, nodes, element, matches; var list = new NodeList(); // Get all the nodes if (this.getElementsByTagNameNS) { nodes = this.getElementsByTagNameNS("*", "*"); } else if (this.getElementsByTagName) { nodes = this.getElementsByTagName("*"); } else { return null; } // Iterate through the nodes for (i = 0; i < nodes.length; i++) { element = nodes.item(i); // Ensure that the hasClassName method has been attached to the element try { matches = true; // Iterate through the class name arguments to check the element has all of them for (j = 0; j < arguments.length && matches; j++) { // See Element.prototype.hasClassName defined in ElementClassName.js. if (!element.hasClassName(arguments[j])) matches = false; } if (matches) list.push(element); } catch(e) { // Error, hasClassName() failed matches = false; } } return list; } } GetElementsByClassName.apply(Document.prototype); GetElementsByClassName.apply(Element.prototype);