Making the save and cancel buttons editable The following code makes a div tag editable and handles the save and cancel buttons. But there is a lot of duplication. How could I remove the duplication on this?

var originalTexts = {};
$("div.edit-panel").find("span").click(function() {
    var panel = $(this).closest('div.simple-panel');
    var text  = panel.find(".info");
    var id = $(this).parent().attr("id");
    panel.find(".edit-panel").addClass('editable');
    text.addClass("content-editable").prop('contenteditable', 'true');
    originalTexts[id] = text.text();
})

$("div.edit-panel").find(".cancel-editable").click(function() {
    var panel = $(this).closest('div.simple-panel');
    var text  = panel.find(".info");
    var id    = $(this).parent().attr("id");
    text.text(originalTexts[id]);
    panel.find(".edit-panel").removeClass('editable');
    text.removeClass("content-editable").prop('contenteditable', 'false');
})

$("div.edit-panel").find(".save-editable").click(function() {
    var panel = $(this).closest('div.simple-panel');
    var text  = panel.find(".info");
    var currentText = text.text();
    text.text(currentText);
    panel.find(".edit-panel").removeClass('editable');
    text.removeClass("content-editable").prop('contenteditable', 'false');
})
How about using just one declaration and an if block? You remove the top three lines by this for each function - 

assuming buttons are &lt;button&gt;

var originalTexts = {};
$("div.edit-panel").find("button,span").click(function(){
    var panel = $(this).closest('div.simple-panel');
    var text  = panel.find(".info");
    var id = $(this).parent().attr("id");
    var currentText = text.text();

    if ($(this).is("span")){
        panel.find(".edit-panel").addClass('editable');
        text.addClass("content-editable").prop('contenteditable', 'true');
        originalTexts[id] = text.text();
    }else if ($(this).hasClass("cancel-editable")){
        text.text(originalTexts[id]);
        panel.find(".edit-panel").removeClass('editable');
        text.removeClass("content-editable").prop('contenteditable', 'false');
    }else if ($(this).hasClass("save-editable")){
        text.text(currentText);
        panel.find(".edit-panel").removeClass('editable');
        text.removeClass("content-editable").prop('contenteditable', 'false');
    }
}); 


You can reduce more codes if you can store the id and other information inside the data attributes of each button. But I don't know the html, so could not suggest on that.