Unfortunately it doesn't work like that in the latest nightly.
What is causing the most confusion is that the three following queries
do not produce the same context:
$("div", document.getElementById("myId"));
$("div", $("#myId"));
$("div", "#myId");
Actually, only the first one result in the element with the id "myId"
to be set as the context.
There is however quite a simple and inexpensive fix for the second and
third selectors:
- The second syntax is currently treated with the following code:
return (context || rootjQuery).find( selector );
A test can be added to check if there is a single DOM node in the
context:
if(context && context.length == 1) context.context = context[0];
return (context || rootjQuery).find( selector );
- The third syntax is treated this way:
return jQuery( context ).find( selector );
we could instead use the second syntax which would effectively check
if there is a single DOM node:
return jQuery( selector, jQuery( context ));
Note that the second syntax is more efficient than the third one, due
to a reduced number of function calls.
This two line fix should make the context parameter behave more
consistently and be easier to understand for developers.
Louis-Rémi Babé
On Aug 14, 1:24 pm, John Resig <[email protected]> wrote:
> > That can't be true, right? It doesn't "search the whole doc".
>
> Correct, it only searches the limited sub-set.
>
> > The "context" property may be "document" but ".myClass" is only
> > searched for within "#myContainer", right? (this is how I see it,
> > after looking at the source)
>
> > I think the main reason people (including me) are confused is because
> > the "context" property does not correspond with the "context"
> > parameter. I'm not too bothered about it but it seems to be causing
> > confusion elsewhere.
>
> Correct - regardless of what's passed in as the context argument, it must be
> translated into a single DOM node, which will act as the root against
> queries will be executed. This node is what is stored in .context.
>
> --John
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"jQuery Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/jquery-dev?hl=en
-~----------~----~----~----~------~----~------~--~---