Bug Tracker

Modify

Ticket #11588 (closed bug: invalid)

Opened 2 years ago

Last modified 2 years ago

.on doesn't work with clone elements

Reported by: rasec <cesarcruz85@…> Owned by:
Priority: low Milestone: None
Component: event Version: 1.7.1
Keywords: Cc:
Blocking: Blocked by:

Description

The .on function apparently doesn't work with elements that has been cloned and appended to the DOM dynamically. I tried it using .live and works perfectly.

.on example:  http://jsfiddle.net/rasec/AdGye/3/

.live example  http://jsfiddle.net/rasec/MTP67/3/

Tested in Firefox 11 and Chromium 17

Change History

comment:1 Changed 2 years ago by sindresorhus

  • Priority changed from undecided to low
  • Resolution set to invalid
  • Status changed from new to closed
  • Component changed from unfiled to event

That's because the element doesn't exist when you bind to it. The normal .on() works like the old .bind().

Either use

event delegation: $(".bet").on('click', ".addbetbutton", function() {});

or live using .on(): $(document).on('click', ".addbetbutton", function() {});

Last edited 2 years ago by sindresorhus (previous) (diff)

comment:2 Changed 2 years ago by rasec <cesarcruz85@…>

My mistake, thanks a lot and sorry for the inconvience

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.