Search code examples
javascriptgetelementsbytagnamespidermonkey

Spidermonkey and getElementsByTagName


I'd like to have getElementsByTagName in a system that supports Spidermonkey. Where could I find source for that function or how can I get that functionality with Spidermonkey?


Solution

  • I added something like this:

    Element.prototype.getElementsByTagName = function(tagName) {
        var elements = [];
        for (var child = this.firstElementChild; child != null; child = child.nextElementSibling) {
            if (child.localName === tagName) {
                elements.push(child);
            }
            elements.pushArray(child.getElementsByTagName(tagName));
        }
        return elements;
    }