I have a created table where I show several records. I want to add update functionality using Ajax ..
I wrote the following code. When I click on any line, it makes all the lines editable. I only want to edit the specific line that I clicked on.
Please indicate to me how to achieve this.
<button type="button"
class="updateUser btn btn-primary btn-xs" data-userId="<?php echo $id; ?>">
<span class="glyphicon glyphicon-pencil"></span>
</button>
$(document).on("click", ".updateUser", function(){
$('tr td:nth-child(2)').each(function () {
var html = $(this).html();
var input = $('<input type="text" />');
input.val(html);
$(this).html(input);
});
});

EDIT - HTML
<table class="table table-hover">
<thead>
<tr>
<th>#</th>
<th>Username</th>
<th>Password</th>
<th>Role</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<tr>
<td>"PHP Dynamic ID "</td>
<td>"PHP Dynamic Username "</td>
<td>"PHP Dynamic Password "</td>
<td>"PHP Dynamic Role "</td>
<td>
<button type="button" class="updateUser btn btn-primary btn-xs" data-userId="<?php echo $id; ?>">
<span class="glyphicon glyphicon-pencil"></span>
</button>
</td>
<td>
<button class="deleteUser btn btn-danger btn-xs" type="button" data-userId="<?php echo $id; ?>">
<span class="glyphicon glyphicon-remove"></span>
</button>
</td>
</tr>
</tbody>
</table>
source
share