Bug Tracker

Opened 12 years ago

Closed 10 years ago

Last modified 6 years ago

#2977 closed bug (fixed)

wrap() methods lose events

Reported by: rodnaph Owned by:
Priority: minor Milestone: 1.4
Component: core Version: 1.4a1
Keywords: clone wrap events Cc:
Blocked by: Blocking:

Description

When using the wrap() method, events I have added to the element are lost (because wrap() uses clone() which doesn't preserve events). Shouldn't jQuery actually preserve events on elements? (or atleast provide the option to preserve them without having to rely on a plugin?)

Example:

$( 'img' ).wrap(

$( '<a></a>' )

.click( doSomething )

);

Change History (6)

comment:1 Changed 12 years ago by rodnaph

This bug is also in 1.2.6.

comment:2 Changed 12 years ago by skorpan

Actually, I seem to have an even worse problem.

var jq = $(elem);
var div = $('<div></div>');
jq.wrap(div);
div.click(function () {
    alert('click!');
});

I click the DIV - nothing happens. So it seems that whenever I use wrap() on a JQuery object, I can't bind any events to it whatsoever. Tested in Firefox 3.0.1 on Windows XP.

comment:3 Changed 11 years ago by dmethvin

Keywords: clone wrap events added

comment:4 Changed 11 years ago by matejr

Please, fix this issue. It's just about adding true as parameter of the clone function called from wrapAll function.

comment:5 Changed 10 years ago by john

Milestone: 1.31.4
Resolution: fixed
Status: newclosed
Version: 1.2.51.4a1

comment:6 Changed 6 years ago by gor.konstantin@…

Hi,

Still can reproduce this bug http://jsfiddle.net/VDQmC/3/

Konstantin.

Note: See TracTickets for help on using tickets.