Bug Tracker

Ticket #3548 (closed bug: invalid)

Opened 6 years ago

Last modified 6 years ago

$(this) breaks chainability when this is a jQuery object

Reported by: dlikhten Owned by:
Priority: major Milestone: 1.3
Component: core Version: 1.2.6
Keywords: Cc: dlikhten, flesler
Blocking: Blocked by:

Description

When chaining and using a custom function that uses and returns $(this) the $(this) call will break the chainability as it will not transfer the pre-destructive states.

Is this behavior valid, and my use case is an invalid use of jQuery extensions or should this behavior be supported?

Change History

comment:1 Changed 6 years ago by flesler

  • Cc dlikhten, flesler added
  • need changed from Review to Test Case

$(this) is a new jQuery object, with no previous states.

The "stack of states" goes with a specific object. You simply need to keep a reference to the original jQuery object.

Why do you pass a jQuery object to jQuery ? simply use 'this'. If you want to save a jQuery object to a var, you simply assing 'this' not $(this).

If you really have a justified reason, you can do:

var $copy = $(this);
$copy.prevObject = this.prevObject;

I'll let you provide a valid use for this before closing. Let me know if I can simply close this.

comment:2 Changed 6 years ago by dmethvin

  • Status changed from new to closed
  • Resolution set to invalid
Note: See TracTickets for help on using tickets.