Bug Tracker

Modify

Ticket #7904 (closed bug: duplicate)

Opened 3 years ago

Last modified 3 years ago

$(element).add(selector) incorrectly uses element as the default context

Reported by: cracked@… Owned by:
Priority: undecided Milestone: 1.next
Component: unfiled Version: 1.4.4
Keywords: Cc:
Blocking: Blocked by:

Description

When doing:

$(element).add(selector)

the context for the selector defaults to element, rather than the document. While this can easily be fixed by explicitly specifying the context, this behavior can have unexpected and undesired results. For example in an HTML document:

// This effectively results in all elements being added
$('body').add('*');

// Surprisingly, the following calls are equivalent, adding
// only the document and its children
$(document.body).add('*');
$(document.body).find('*').andSelf();

Change History

comment:1 Changed 3 years ago by cracked@…

Note a typo in the last comment, which apparently I can't edit: [...] adding only the document body and its children

comment:2 Changed 3 years ago by ajpiano

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

comment:3 Changed 3 years ago by ajpiano

Duplicate of #7853.

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.