javascript - How do I get the value of td and pass it on input in each td element? -
i'm still newbie in jquery world :) making looks , problem getting text in each <td>
, passing input.
i have code:
<div class="grid-l1"> <table> <tr> <td> testing <input type="text"> </td> </tr> <tr> <td> testing 2 <input type="text"> </td> </tr> </table> <span class="edit">edit</span> <span class="update">update</span> </div>
here's jquery code:
<script> $(document).ready(function(){ $('body').on('click', '.edit', function() { $(this).hide(); $('table tr td input').show(); $('.update').show(); }); $('.update').click(function(){ $(this).hide(); $('table tr td input').hide(); $('.edit').show(); }); }); </script>
how td text , pass each input on td element when click edit ?
i appreciate every response guys doing. in advance.
you need text()
of td
contains input
, set it's value. try this:
$('body').on('click', '.edit', function() { $(this).hide().closest('div').find('table input').val(function() { return $.trim($(this).closest('td').text()); }); $('table tr td input, .update').show(); });
Comments
Post a Comment