I am trying to change the table cell from ‘span’ type to ‘input’ on click and then back to ‘span’ on blur but it isn’t working as given in here:
Convert table cells to text-boxes with JQuery
here is the javascript code:
<script type="text/javascript">
$(document).ready(function() {
$('#assets').click(function () {
$('tr td:nth-child(3)').each(function () {
var html = $(this).html();
var input = $('<input type="text" />');
input.val(html);
$(this).html(input);
});
});
});
</script>
and here is the document body
<body>
<div id="content">
<table id="assets">
<tr>
<td class="asset_name"><span>Name</span></td>
<td class="asset_value"><span>ast1</span></td>
<td class="asset_name"><span>Location</span></td>
<td class="asset_value"><span>Loc-1</span></td>
</tr>
<tr>
<td class="asset_name"><span>Name</span></td>
<td class="asset_value"><span>ast2</span></td>
<td class="asset_name"><span>Location</span></td>
<td class="asset_value"><span>Loc-2</span></td>
</tr>
</table>
</div>
</body>
using jQuery 1.7.2
What’s wrong here ? Please help !
Thanks!!
Update: only need to change the cells with class=’asset_value’ and only one cell at a time not all. Also, it should change back to span on blur..
Try this :
this will change single cell on click and revert back to span on blur.