I have some <tr>
elements on my page with a click()
event attached to an image that sits inside each one. I use this code
$(this).clone(true).appendTo("table#foo");
to do the following:
- copy those
<tr>
s into a different table - preserve the click events on the images inside the
<tr>
s (because of thetrue
argument)
All of that works fine. Now I have added a jQuery Listen event to those <tr>
s, so that a user doesn't have to aim precisely: he/she can click anywhere on the <tr>
and I can pass the click to the image.
It's coded like this:
$('tr.record').listen('click','td',function(){
$(this).parent().find("img.clickable").click();
});
The listen() event works fine on the original item, but on the cloned item, the listen() event fails. The image's click event still works fine.
Here is what Firebug tells me:
m(this, e.type) is undefined
...and it references line 9 of jquery.listen-1.0.3-min.js.
How can I can make the listen() event work on the cloned elements?
Update
By default, jQuery doesn't copy events on cloned elements, but this plugin is made to do that.
Meanwhile, the author of the listen() plugin suggested a different strategy - see my answer below.