Hello all.

I've just find an strange behaviour while selecting by `id` using `find`.

Take this HTML fragment:

    <div id="nowrap"></div>
    <div id="wrap">
            <div id="heroe">I'm the heroe</div>
    </div>

This code will result in a one element collection:

    $("#nowrap").find("#hero");

This seems to be result of performance optimization when we use an
`id` as the selector. Can be easily circumvented by usign

    $("#nowrap").find("div#hero");

or

    $("#nowrap").find("[EMAIL PROTECTED]");

Should this be considered a bug? A feature?

Maybe an explanation of why I'm using `id`s in a context selection
would be useful, so here it is:

I'm working on a heavily event oriented app. The events are assigned
both through `ready` --for the full document-- and a callback for each
XHR loaded content. So I've defined a collection of functions which
should be executed:

    var initFuncions = [
        someFunction, someOtherFunction
    ];

    function someFunction(context) {
        $("someSelector", context).bind("somevent", someHandler);
    }


And a "runner" for them:

    function init(context) {
        context = context || document;
        for (var i = 0, len = initFunctions.length; i < len; i++) {
            initFunctions[i](context);
        }
    }

So, to initialize events for the full doc:

    $(init);

And to initialize events for just a part of the DOM (which has been
loaded through `$.ajax`):

    // this is part of the callback function
    $(holder).append(result);
    init(holder);

Please forgive the long --and maybe unintelligible-- explanation.

Then again, bug or feature?
-- 
Choan
<http://choangalvez.nom.es/>

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to