views:

818

answers:

2

Hello, I'm sure this is simple but I'm banging my head!

I'm using the excellent jQuery plugin editable (http://www.appelsiini.net/projects/jeditable). Users can create a form on the fly, and click to edit the title, the body of the text, whatnot.

Every time the user creates a new question, I rebind the plugin like so:

$('.edit').editable()

Where every element with class 'edit', should be editable.

The problem is, previous 'edit' elements seem to get double bound... that is, when you click to edit them, an input field shows up, containing the following:

<input class="">

Which makes sense since it's getting bound twice (or more). How best to approach this issue? My instinct is to unbind the plugin on all 'edit' elements and then rebind it but I don't know how to do this.

Thanks for your help

+1  A: 

Scope your selector to just the newly created form.

$('<form>...</form>').appendTo('someDiv')
                     .find('.edit')
                     .editable();

or

$('form:last').find('.edit')
              .editable();

Note that the selectors for the form are just examples. You just need to find the right form and only apply the editable plugin to the items decorated with the edit class within it.

tvanfosson
I understand. This is probably a better way to do it then what I was thinking, so I'll give this a shot, but I'm still curious about the original question - unattaching plugins
thekevinscott
You'd have to know what events were added by a particular plugin and remove those event/function pairs using the unbind() method. This is probably best provided by each plugin, for example the jQuery UI dialog plugin does this via the destroy method: http://docs.jquery.com/UI/Dialog#method-destroy
tvanfosson
+2  A: 

A "plugin" is just a function added to jQuery.fn. Unless the creator defines a remove or destroy method, the function cannot be reversed.

Edit: the editable function, when given the parameter 'destroy', unbinds the plugin.

Eric