Question

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?

Was it helpful?

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top