I know this has been asked a couple of times but this requirement is a bit different. Here is my HTML:
<table class="display table table-striped" id="reportTable">
<thead>
<tr>
<th width="2%"><input id="all" name="select_all" value="1" type="checkbox"></th>
<th>Date</th>
<th>User</th>
<th><span>Comments</span></th>
<th width="4%">Action</th>
</tr>
</thead>
<tbody>
<td>
<i class="fa fa-spinner fa-spin"></i>
<span> </span>
Loading...
</td>
<td></td>
<td></td>
<td></td>
<td></td>
</tbody>
</table>
I am filling up this table using javascript
function getTableRow(report) {
var id = report.id;
var date = report.create_date;
var user = report.created_by;
var comments = report.comments;
return [
"<input name='' value='1' type='checkbox'>",
"<a href=\"/reports/" + id + "\">" + date + "</a>",
user,
<span id=\"" + id + "\"" + "class=\"asset_value\">" + comments + "</span>,
'<button class="button" onClick="deleteReport(this, \'' + id + '\')"><i class="fa fa-trash-o"></i></button>'
];
}
What I want is when I click on the the 3rd column(comments) of any row I should get an input box and when I click out it should get replaced by the content I have typed in the input box.
$(document).ready(function() {
$('#reportTable').on('click', 'span', function() {
var $e = $(this);
if($e.attr('class') === 'asset_value') {
var val = $(this).html();
$e.html('<input type="text" value="'+val+'" />');
var $newE = $e.find('input');
$newE.focus();
}
$newE.on('blur', function() {
$(this).parent().html('<span>'+$(this).val()+'</span>');
});
});
});
But this doesn't work.