Search code examples
javascriptjqueryjeditable

jeditable - multiple editable fields, trigger the right one to edit


Im using the jeditable jquery plugin.

i have multiple separate ediatable areas, so when an edit button is clicked i want the relevant editable area to be in edit mode.

Im currently doing something crazy like this:

$(".edit_trigger").bind("click", function () {

            $(this).parent().parent().prev().prev().prev().trigger("edit");
        });

what is the better way to do this? as it keeps breaking as i change the layout.


Solution

  • Assuming .edit_trigger is a button you can include a ref="ID OF EDIT ELEMENT" on the button than change your code to.

    $(".edit_trigger").bind("click", function () {
    
            $('#' + $(this).attr("ref")).trigger("edit");
        });