Creating JEditable work on new elements (.live)

I use the JEditable plugin for in-place editing.

I have a setup function that calls .editable() for all the relevant classes. The problem is that I have recently added elements that I would like to make editable. Obviously, when added, .editable() will never be called on them.

In other words, I want to get the effect that the jquery live() function does, but for the editable() function.

My current workaround seems ugly to me ( redscribe_button is the button that you need to click to edit the text):

 $(".redescribe_button").live("click", function(click_event) { click_event.preventDefault(); $(".editable", $(this).parent().parent()).editable("/temp/", { event: "make_editable", indicator : 'Saving...', tooltip : 'Click to edit...' }); $(".editable", $(this).parent().parent()).trigger('make_editable'); }); 

In other words, I just call .editable every time the edit button is clicked.

Any ideas for a better solution?

+6
javascript jquery jeditable
source share
2 answers

Calling an edit more than once on an element has no side effects, does it? So why not just repeat the setup every time something changes.

+3
source share

I just approached this issue and solved it in a more elegant way (IMHO).

 $('.jqEdit').live('click',function(event) { event.preventDefault(); $(this).editable('save.php') }); 
+5
source share

All Articles