Context is either a dom node, a document, or recently a jQuery object with the like. Context is merely used for establishing a dom node as a parent, and in the case of a document is necessary to know what document to use to create new nodes for. Thinking that $("[name]", "#people"); is the same as $("#people[name]"); is wrong on multiple levels. $("[name]", $("#people")); actually means $("#people [name]"); and the contex is not meant to be used that way. In fact trying to think that way makes things confusing and reduces code readability because you are mixing up order. If you want to build queries like this then I'd recommend you push for the inclusion of my alternate proposed format: $("#selector", "[selector]", ".selector", ...); Which makes proper sense since you are building up selectors in order (even has potential performance benefits if someone is adventurous since I'd explicitly say to not rely on any consistent return for .end() when using it). It's even more useful when you throw widget objects into the mix.
~Daniel Friesen (Dantman, Nadir-Seen-Fire) DBJDBJ wrote: > My question/comment : What is a CONTEXT LOGIC in jQ ? I think it > should be : dom node inside which is the result set to be found? > The dom node inside which is jQuery to use the selector given. Default > is document. > > If I read it right , jQ doc says that context type can be (only?) dom > node or jQuery instance. So I expected that if I give context as a > string it will be takens as selector for the jQuery, which will > eventualy spill out a single dome node to be used as a context. And > that > way one can speed up her code, because querying inside the known dom > element must be quicker than querying inside the whole document, each > time. finding on the branch is faster that finding from the root of > the tree. > > But it seems that if string is given as a context , the selector get's > it as a prefix and context is a dom document ? So : > > $("[name]", "#people") is the same as saying $("#people[name]", > document ) , because jQ makes it into this. > > While one might expect the above to be translated to : $("[name]", > document.getElementById("people") ) , which could considerably speed > up the slection ... > > A quick sample I have made (quickly) is here: http://jsbin.com/avowu/edit > > // context is correctly reported by jQ > $("[name]", document.getElementById("people")).formula( log ) ; > > // this.context is reported by jQ as HTMLDocument ? > // this.selector is prefixed with context > $("[name]", "#people") ; > > Is this "by design" ? Maybe jQ does this : > > 1 :: jQuery("#people").find("[name]") > 2 :: this.context = "#people" + "[name]" > > So that plugins can see the context which actually was used ? So the > line : > $("[name]", "#people") > after all IS actually making things faster ? And I am (or I was) > confused with the value of this.context and this.selector, available > to me inside a plugin ? But then I think I can;t be right here, > because it would be much better to have the selector and context, as > originaly > given by the user : > > 1 :: this.context = "#people" ; this.selector = "[name]" ; > 2 :: jQuery(context).find(selector) > > After this plugins will see the original selector and context. > Provided my assumptions are correct. > > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "jQuery Development" group. To post to this group, send email to jquery-dev@googlegroups.com To unsubscribe from this group, send email to jquery-dev+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/jquery-dev?hl=en -~----------~----~----~----~------~----~------~--~---