Bug Tracker

Ticket #5202 (closed bug: fixed)

Opened 5 years ago

Last modified 5 years ago

Simple .selector fix for when .pushStack 'selector' == jQuery object

Reported by: cowboy Owned by: flesler
Priority: major Milestone: 1.4
Component: core Version: 1.3.2
Keywords: Cc: cowboy
Blocking: Blocked by:

Description

The appendTo, prependTo, insertBefore, insertAfter, replaceAll methods all expect a selector string argument, but will work with a DOM node or jQuery object, because this argument is first passed through jQuery(). Unfortunately, pushStack's setting of the .selector property doesn't behave as well as it should with a non-string selector. This fix takes care of that.

Diff:  http://benalman.com/code/jquery/src/pushstack_selector.diff

Screenshot:  http://gyazo.com/8b42b191ece9022e143028bed3124f52.png

$('<div id="test"/>').prependTo( 'body' );

var sel = '#test',
  elem = $(sel);

console.log( $.fn.jquery );
console.log( $('<span>1<\/span>').appendTo( sel ).selector );
console.log( $('<span>2<\/span>').appendTo( elem ).selector );
console.log( elem.selector );

(function($){

  var sel = '#test',
    elem = $(sel);

  console.log( $.fn.jquery );
  console.log( $('<span>3<\/span>').appendTo( sel ).selector );
  console.log( $('<span>4<\/span>').appendTo( elem ).selector );
  console.log( elem.selector );

})($$$); // $$$ is the latest jQuery w/ my patch applied

output:

1.3.2
.appendTo(#test)
.appendTo([object Object])
#test
1.3.3pre
.appendTo(#test)
.appendTo(#test)
#test

Change History

comment:1 Changed 5 years ago by flesler

  • Cc cowboy added
  • need changed from Review to Commit
  • Status changed from new to assigned
  • Component changed from unfilled to core
  • Owner set to flesler

comment:2 Changed 5 years ago by flesler

  • Status changed from assigned to closed
  • Resolution set to fixed

Fixed at [6547].

Note: See TracTickets for help on using tickets.