I think this is a little different from what was originally asked for.
Something along the lines of:

jQuery.fn.cloneWithEvents = function( deep ) {
  var old = this;
  return this.clone( deep ).cloneEventsFrom( old );
};

This way you can do the cloning (and the event cloning) all in one operation:

$("div.toggle").cloneWithEvents().appendTo("#container");

--John

On 1/25/07, Brandon Aaron <[EMAIL PROTECTED]> wrote:
> I've noticed several times on the list people asking why .clone()
> doesn't clone the events along with the elements. No more worries ...
> now you can clone those events if you need too!
>
> var $elements = $('.elements');
> $elements
>     .clone()
>     .cloneEventsFrom($elements);
>
> There is also a .cloneEventsTo() which acts like .appendTo().
>
> var $elements = $('.elements');
> var $clonedElements = $elements.clone();
> $elements.cloneEventsTo($cloneElements);
>
> You can find this plugin in SVN:
> http://jquery.com/dev/svn/trunk/plugins/cloneEvents/cloneEvents.js?format=txt
>
> You can run the unit tests here:
> http://brandon.jquery.com/plugins/cloneEvents/test/unit.html
>
> --
> Brandon Aaron
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to