Skip to main content

Bug Tracker

Side navigation

#11588 closed bug (invalid)

Opened April 13, 2012 11:36AM UTC

Closed April 13, 2012 11:49AM UTC

Last modified April 13, 2012 11:59AM UTC

.on doesn't work with clone elements

Reported by: rasec <cesarcruz85@gmail.com> Owned by:
Priority: low Milestone: None
Component: event Version: 1.7.1
Keywords: Cc:
Blocked by: Blocking:
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

Attachments (0)
Change History (2)

Changed April 13, 2012 11:49AM UTC by sindresorhus comment:1

_comment0: That's because the element doesn't exist when you bind to it. \ \ Either use \ event delegation: $(".bet").on('click', ".addbetbutton" \ or live using .on(): $(document).on('click', ".addbetbutton"1334317866384082
component: unfiledevent
priority: undecidedlow
resolution: → invalid
status: newclosed

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() {});

Changed April 13, 2012 11:59AM UTC by rasec <cesarcruz85@gmail.com> comment:2

My mistake, thanks a lot and sorry for the inconvience