Duh! I'll add the cloneWithEvents() method to the plugin shortly. I
was thinking how to make the plugin as flexible as possible and allow
for other use-cases instead of just with clone. Lets say for example
that you have an unordered list and each list item has events. Then
you add some more list items via AJAX but need to rebind the events.
Just use the cloneEventsFrom method.
Thanks John ... I believe that completes this plugin.
--
Brandon Aaron
On 1/25/07, John Resig <[EMAIL PROTECTED]> wrote:
> 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/
>
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/