I have a table of records. when a user double-clicks on each <td> it converts to <input type="text"> and after click outside it, it must be saved.
but the problem is when click inside of the specific <td> it does that.
//double click ->then convert to input
$(document).on('dblclick', 'tbody tr td', function() {
var tmp = $(this).text();
var name = $(this).attr("data-name");
$(this).html('<input type="text" id="tmp_ed" value="' + tmp + '"/>');
$(document).on('click', function() {
if ($(this).attr('id') !== "tmp_ed") {
var item = $('#tmp_ed').val();
var tr = $('#tmp_ed').parent().parent();
var id = tr.find('i').attr('id');
var update = {
id: id,
request: "update",
val: item,
column: name
};
$.ajax({
url: "update.php",
method: "POST",
data: update,
success: function(e) {
alert(e);
}
});
$(this).parent().html(item);
$(this).remove();
}
});
});