Skip to main content

Bug Tracker

Side navigation

#5553 closed bug (worksforme)

Opened November 26, 2009 08:24AM UTC

Closed December 05, 2009 02:34AM UTC

What is 'context' , in the context of jQuery ?

Reported by: dbjdbj Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: context Cc:
Blocked by: Blocking:
Description

I think, we need a clear defintion of the 'context'.

The second argument to the $() function.

I think we are pretty close.

But I found this in the init :

 // Handle $(DOMElement)
  if (selector.nodeType) {
        this.context = this[0] = selector;
        this.length = 1;
        return this;
  }

Which confused me? I thought that context is the parent element, inside which selector is applied ? Like this:

jQuery( context ).find( selector ) ; 

According to this , the above part of init() should be changed to this:

 // Handle $(DOMElement)
       if (selector.nodeType) {
           this[0] = selector;
            this.context = selector.parentNode || selector;
            this.length = 1;
            return this;
        }

Otherwise, this:

jQuery( selector ).find( selector ) ; 

would be also valid ? Can context and selector be ever a same element ?

It seems clarification is required ...

--DBJ

Attachments (0)
Change History (3)

Changed November 27, 2009 04:15AM UTC by dmethvin comment:1

resolution: → invalid
status: newclosed

This would be best discussed on jQuery-dev since it's not a bug report as far as I can tell.

Changed November 27, 2009 09:17AM UTC by dbjdbj comment:2

resolution: invalid
status: closedreopened

Please confirm that selector and context *can* be the same node.

If yes, I was wrong.

Many thanks: Dusan

PS: no, I will not "go on" re-opening the closed tickets ;o)

Changed December 05, 2009 02:34AM UTC by john comment:3

resolution: → worksforme
status: reopenedclosed

In the case of a single DOM node being passed in to jQuery it's acting as both the selector and the context - it's a special case.