Skip to main content

Bug Tracker

Side navigation

#5202 closed bug (fixed)

Opened September 10, 2009 07:24PM UTC

Closed September 14, 2009 06:04PM UTC

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
Blocked by: Blocking:
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
Attachments (0)
Change History (2)

Changed September 14, 2009 06:04PM UTC by flesler comment:1

cc: → cowboy
component: unfilledcore
need: ReviewCommit
owner: → flesler
status: newassigned

Changed September 14, 2009 06:04PM UTC by flesler comment:2

resolution: → fixed
status: assignedclosed

Fixed at [6547].