robnyman / domassistant

Automatically exported from code.google.com/p/domassistant
1 stars 0 forks source link

$ with multiple arguments does not work #9

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. selecting multiple elements with multiple arguments with $ like the manual 
suggests  – $("#container", "#navigation .important-item", "#content"); – 
does not return the expected 
results, but just the element(s) matching the first argument.

What is the expected output? What do you see instead?
Output should contain all matched elements to all arguments.

What version of the product are you using? On what operating system?
2.7.1.1

Please provide any additional information below.
I patched the $ function, it now looks like that:

        $ : function () {
            var elm = new HTMLArray();
            if (!document.getElementById) return elm;

            for (var i = 0, arg; arg = arguments[i]; i++) {
                if (typeof arg === "string") {
                    arg = arg.replace(/^[^#]*(#)/, "$1");
                    if (/^#[\w\u00C0-\uFFFF\-\_]+$/.test(arg)) {
                        var idMatch = DOMAssistant.$$(arg.substr(1), false);
                        if (idMatch) {
                            elm.push(idMatch);
                        }
                    }
                    else {
                        var tmpElms = DOMAssistant.cssSelection.call(document, arg);
                        for (var j = 0, tmpElm; tmpElm = tmpElms[j]; j++) {
                            elm.push(DOMAssistant.$$(tmpElm));
                        }
                    }
                }
                else if ((typeof arg === "object") || (typeof arg === "function" && typeof 
arg.nodeName !== "undefined")) {
                    elm.push(DOMAssistant.$$(arg));
                }
            }
            return elm.length == 1 ? elm[0] : elm;
        }

Original issue reported on code.google.com by wif...@gmail.com on 2 Jun 2008 at 9:37

GoogleCodeExporter commented 9 years ago

Original comment by chengh...@gmail.com on 3 Jun 2008 at 11:32

GoogleCodeExporter commented 9 years ago
Through experimentation, I have discovered that the documentation is incorrect. 
The
separate elements should not be broken into different function parameters, but
comma-separated within a single parameter.

Not working (per docs):
$("#container", "#navigation .important-item", "#content");

Working:
$("#container, #navigation .important-item, #content");

Original comment by neil.mon...@gmail.com on 9 Jul 2008 at 5:48

GoogleCodeExporter commented 9 years ago
Fixed in next release.

Both
$("#container", "#navigation .important-item", "#content");
and 
$("#container, #navigation .important-item, #content");
will work.

Original comment by chengh...@gmail.com on 29 Jul 2008 at 2:43