Bug Tracker

Modify

Ticket #5434 (closed enhancement: fixed)

Opened 4 years ago

Last modified 4 years ago

$.fn.add( selector, context )

Reported by: rkatic Owned by:
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: add, context Cc:
Blocking: Blocked by:

Description

  1. The optional context will be applied on evolving the selector.
  1. If the context argument is not given, then at lest use the same document.

 Discussion

Here the expected implementation:

Query.fn.add = function( selector, context ) {
    return this.pushStack( jQuery.unique( jQuery.merge(
        this.get(),
        typeof selector === "string" ?
            jQuery( selector, context
                || this.context && this.context.ownerDocument || this.context)
                || this[0] && (this[0].ownerDocument || this[0]) ) :
            jQuery.makeArray( selector )
    )));

};

Change History

comment:1 Changed 4 years ago by john

  • Status changed from new to closed
  • Resolution set to fixed
The more I thought about it, the less sense "
this.context && this.context.ownerDocument" made. The .add() method should use the context specified by the root selector call.

I've implemented this change along with test cases. Thanks for the preliminary patch!  http://github.com/jquery/jquery/commit/b0fe380cf89564305646bbd55d1fd7bd210fd591

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.