TheTruth TheTruth - 1 month ago 8x
CSS Question

jQuery replaceWith Inside Loop malfunction

So here's what i was trying to do. if I click on update button, the text on the left side will be an INPUT box like below:
Click the update button and the text on the left will be an input box

BUT what's really happening is all the text on the left side is getting replaced with INPUT box, image here:
all text left side is affected

how do I use a unique id or something? sorry I'm new to this jQuery stuff. And can you please explain how I can edit the table affected on MySQL?

code here:

<table class="table no-margin">
<th width="250px">Category</th>
<th width="20px"> </th>
<th width="20px"> </th>
while ($rows = mysql_fetch_array($result)) {
$tcategory = $rows['vCategory'];
$cid = $rows['id'];
<?php echo '<div class="editable">'. $tcategory .' </div>'; ?>

<td><button id="edit" class="btn btn-block btn-xs btn-success"> Update</button> </td>
<td><button class="btn btn-block btn-xs btn-danger"> Delete</button> </td>

<script src=""></script>
$("#edit").click(function() {
var $this = $(this);
if($this.attr('editing') != '1') {
$this.text('Save').attr('editing', 1);
$(document).find('.editable').each(function() {
var input = $('<input class="editing" />').val($(this).text());
}else {
$(document).find('input.editing').each(function() {
var div = $('<div class="editable" />').text($(this).val());
<td><input type="text" class="form-control" name="addCategory" placeholder="Enter New Category"></td>
<td><input type="submit" class="btn btn-block btn-sm btn-success" value="Add"></td>


Ish Ish

Put same class in all edit button. Remove the edit id. Remember IDs are unique.Try something like this:


$(this).closest('tr').find('.editable').each(function() {

instead of

 $(document).find('.editable').each(function() {