Unbind jquery plugins

I'm sure it's easy, but I hit my head!

I use the excellent jQuery plugin for editing ( http://www.appelsiini.net/projects/jeditable ). Users can create a form on the fly, and then click to change the name, text, text, or something else.

Every time a user creates a new question, I rewrite the plugin like this:

$('.edit').editable()

Where each element with the class 'edit' should be editable.

The problem is that the previous “edit” items seem to get double snapped ... that is, when you click to edit them, an input field appears containing the following:

<input class="">

This makes sense as it gets the binding twice (or more). What is the best approach to this problem? My instinct is to untie the plugin on all the "edit" elements and then repeat it, but I don’t know how to do it.

thanks for the help

+1
source share
2 answers

A "plugin" is simply a function added to jQuery.fn. If the creator does not define a delete or destroy method, the function cannot be undone.

Edit: when editing a parameter, an editable function 'destroy'unties the plugin.

+5
source

Copy your selector to the form you just created.

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

or

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

, . , edit.

+1

Source: https://habr.com/ru/post/1737897/


All Articles