Export to GitHub

getelementsbyclassname - issue #2

IE7 throws "Object doesn't support this property or method" when searching inside an element


Posted on Dec 3, 2009 by Grumpy Bird

What steps will reproduce the problem? 1. In IE7, call the 3-parameter version of getElementsByClassName, searching inside a div, eg getElementsByClassName("myclass", "span", document.getElementById("someContainerDiv"));

Expected Output: Array of elements returned.

Actual Output: "Object doesn't support this property or method" exception

What version of the product are you using? On what operating system? js version: 1-0-1.
IE7 on Win2k

Comment #1

Posted on Dec 8, 2009 by Grumpy Ox

Can't reproduce the error. Tested code (below) works in IE 7 as well:

Testing getElementsByClassName

<script type="text/javascript">
    /*
        Developed by Robert Nyman, http://www.robertnyman.com
        Code/licensing: http://code.google.com/p/getelementsbyclassname/
    */
    var getElementsByClassName = function (className, tag, elm){
        if (document.getElementsByClassName) {
            getElementsByClassName = function (className, tag, elm) {
                elm = elm || document;
                var elements = elm.getElementsByClassName(className),
                    nodeName = (tag)? new RegExp("\\b" + tag + "\\b", "i") : null,
                    returnElements = [],
                    current;
                for(var i=0, il=elements.length; i<il; i+=1){
                    current = elements[i];
                    if(!nodeName || nodeName.test(current.nodeName)) {
                        returnElements.push(current);
                    }
                }
                return returnElements;
            };
        }
        else if (document.evaluate) {
            getElementsByClassName = function (className, tag, elm) {
                tag = tag || "*";
                elm = elm || document;
                var classes = className.split(" "),
                    classesToCheck = "",
                    xhtmlNamespace = "http://www.w3.org/1999/xhtml",
                    namespaceResolver = (document.documentElement.namespaceURI === xhtmlNamespace)?

xhtmlNamespace : null, returnElements = [], elements, node; for(var j=0, jl=classes.length; j"; elm = elm || document; var classes = className.split(" "), classesToCheck = [], elements = (tag === "" && elm.all)? elm.all : elm.getElementsByTagName(tag), current, returnElements = [], match; for(var k=0, kl=classes.length; k

    window.onload = function () {
        var apa = getElementsByClassName("myclass", "span",

document.getElementById("someContainerDiv")); alert(apa); };

One One One

Status: Invalid

Labels:
Type-Defect Priority-Medium