I have an edit button in every row of a bootstrap interactive table. I am trying to toggle the button glyphicons and based on its current state, make the corresponding row editable.
<td><button type="button" id="edit" value="" class="btn btn-lg btn-link" data-toggle="tooltip" title ="Edit" style="color: black"><i class="glyphicon glyphicon-edit"></i></td>
And the Javascript is as follows
$(document).ready(function () {
$("#edit").click(function () {
var currentTD = $(this).parents('tr').find('td');
if( $(this).find('i').hasClass('glyphicon-edit'))
{
currentTD = $(this).parents('tr').find('td');
$.each(currentTD, function () {
$(this).prop('contenteditable', true);
$(this).css('background','yellow');
});
}
else if( $(this).find('i').hasClass('glyphicon-ok-circle'))
{
$.each(currentTD, function () {
$(this).prop('contenteditable', false);
$(this).css('background','');
});
}
$(this).find('i').toggleClass('glyphicon-edit').toggleClass('glyphicon-ok-circle');
})
});
The issue is that I am only able to do this to the first row. I am not sure why this is happening. New to web stuff here.