Your code with the button click is too complicated. I have reduced it by making it easier to understand.
$(document).ready(function () {
$('.editbtn').click(function () {
var currentTD = $(this).parents('tr').find('td');
if ($(this).html() == 'Edit') {
$.each(currentTD, function () {
$(this).prop('contenteditable', true)
});
} else {
$.each(currentTD, function () {
$(this).prop('contenteditable', false)
});
}
$(this).html($(this).html() == 'Edit' ? 'Save' : 'Edit')
});
});
Code Explained:
1) Get all the tds within tr using below code
var currentTD = $(this).parents('tr').find('td');
2) Then as usual iterate through each td
s and change its contenteditable
property like below
$.each(currentTD, function () {
$(this).prop('contenteditable', true)
});
Updated JSFiddle
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…