Bug Tracker

Modify

Ticket #7043 (closed feature: duplicate)

Opened 3 years ago

Last modified 3 years ago

Error when unbind is called on non-element

Reported by: scott_h Owned by:
Priority: Milestone: 1.4.3
Component: event Version: 1.4.2
Keywords: Cc:
Blocking: Blocked by:

Description

jQuery.data() works with non-element targets. Therefore, jQuery events should work with non-element targets.

var a = {};
jQuery(a).bind("x", function() { console.log("event fired on non-element target") });
jQuery(a).trigger("x"); //=> "event fired on non-element target"
jQuery(a).unbind("x"); //=> TypeError: Result of expression 'elem.removeEventListener' [undefined] is not a function. [jquery.js, line 2070]
jQuery(a).trigger("x"); //=> "event fired on non-element target"

They do, except for unbind() which throws an error. I realise this isn't intended use of jQuery and may never be officially supported since other methods like append() will throw errors too, but custom event targets are so useful and this is potentially be a very minor change.

Change History

comment:1 Changed 3 years ago by dmethvin

Dup of #6184.

comment:2 Changed 3 years ago by snover

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

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.