For The code below, when the button is clicked, it's supposed to update the name of the text. ie hisally, hellosally, supsally, but instead the current is hitomsally, hellotomsally, suptomsally. i m wondering is there any way to update the name while keeping the text hi,hellop and sup. Many thanks
$(".ok").on('click', function() {
var set = $(this).closest('tr').find('.done').val();
if (set) {
$(this).closest('tr').find('.text').each(function() {
$(this).val($(this).attr("data-value") + set);
})
}
});
<table>
<tr>
<td>
<input type="button" value="ok" class="ok"></td>
<td>done<input type="text" value="sally" class="done" \> </td>
<td>text1<textarea class="text" data-value="hitom">hitom</textarea> </td>
<td>text2<textarea class="text" data-value="hellotom">hellotom</textarea> </td>
<td>text3<textarea class="text" data-value="suptom">suptom</textarea> </td>
</tr>
</table>
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>