Bug Tracker

Opened 13 years ago

Closed 13 years ago

#5553 closed bug (worksforme)

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

Change History (3)

comment:1 Changed 13 years ago by dmethvin

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.

comment:2 Changed 13 years ago by dbjdbj

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)

comment:3 Changed 13 years ago by john

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.

Note: See TracTickets for help on using tickets.