Bug Tracker

Modify

Ticket #5553 (closed bug: worksforme)

Opened 4 years ago

Last modified 4 years ago

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:
Blocking: Blocked by:

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

comment:1 Changed 4 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid

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

comment:2 Changed 4 years ago by dbjdbj

  • Status changed from closed to reopened
  • Resolution invalid deleted

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 4 years ago by john

  • Status changed from reopened to closed
  • Resolution set to worksforme

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.

Please follow the  bug reporting guidlines and use  jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

View

Add a comment

Modify Ticket

Action
as closed
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.