Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#7242 closed feature (wontfix)

Trigger an event when an element is removed

Reported by: Glen.84 Owned by: Rick Waldron
Priority: low Milestone:
Component: manipulation Version: 1.4.3
Keywords: Cc: Rick Waldron, scott.gonzalez
Blocked by: Blocking:


Please trigger an event when an element is removed (using $.fn.remove()).

See: http://stackoverflow.com/questions/2200494/jquery-trigger-event-when-an-element-is-removed-from-the-dom

This should really be built-in IMHO, as it's not nice having to overwrite jQuery functions.

Change History (10)

comment:1 Changed 12 years ago by snover

Component: unfiledmanipulation
Keywords: needsreview added
Milestone: 1.5
Priority: undecidedlow

May be bikeshed/feature creep. Marking for review.

comment:2 Changed 12 years ago by Glen.84

It's interesting to note that jQuery UI Widget actually triggers a "remove" event, so it's not such a unique requirement.

It's also not likely to require much code to implement.

comment:3 Changed 12 years ago by Rick Waldron

Cc: Rick Waldron added

comment:4 Changed 12 years ago by Rick Waldron

Owner: set to Rick Waldron
Status: newassigned
Last edited 12 years ago by Rick Waldron (previous) (diff)

comment:5 Changed 12 years ago by Rick Waldron

Milestone: 1.5

retargeted to 1.5

comment:6 Changed 12 years ago by scottgonzalez

Cc: scott.gonzalez added

comment:7 Changed 12 years ago by dmethvin

Use rwaldron's code and only pay the size/performance penalty when needed.

comment:8 Changed 12 years ago by john

Resolution: wontfix
Status: assignedclosed

Yeah, I don't think that this is something that jQuery can reasonably implement without causing performance problems for many applications. (And even if it's limited to only those applications that ask for remove - it will be quite slow.)

comment:9 Changed 12 years ago by scottgonzalez

Just to provide some details in case this ticket is ever referenced in the future:

jQuery UI does not fully trigger an event on remove. We use .triggerHandler() for performance and to ease implementation (we never have to check event.target since there's no bubbling).

rwaldron's solution isn't sufficient since elements are removed in many ways that don't go through .remove(). For example, .html( "" ) will remove all descendants.

jQuery core probably shouldn't provide a single DOM mutation event without providing all reasonable mutation events. There are obvious use cases where remove is useful on its own, but I'm not sure that even if there weren't performance issues that jQuery should implement just remove.

comment:10 Changed 12 years ago by Rick Waldron

Keywords: needsreview removed

To clarify, that fiddle was not intended to be a proposed core implementation, just a "plugin" to satisfy the OP

Note: See TracTickets for help on using tickets.