Skip to main content

Bug Tracker

Side navigation

#2977 closed bug (fixed)

Opened June 04, 2008 02:24PM UTC

Closed December 08, 2009 08:41PM UTC

Last modified November 16, 2013 03:20PM UTC

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 )

);

Attachments (0)
Change History (6)

Changed June 05, 2008 04:33PM UTC by rodnaph comment:1

This bug is also in 1.2.6.

Changed August 12, 2008 11:03AM UTC by skorpan comment:2

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.

Changed January 18, 2009 12:05AM UTC by dmethvin comment:3

keywords: → clone wrap events

Changed March 31, 2009 06:45PM UTC by matejr comment:4

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

Changed December 08, 2009 08:41PM UTC by john comment:5

milestone: 1.31.4
resolution: → fixed
status: newclosed
version: 1.2.51.4a1

Changed November 16, 2013 03:20PM UTC by gor.konstantin@gmail.com comment:6

Hi,

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

Konstantin.