I have some code that allows for a specific table to have the last row duplicated:
<script>
$(document).ready(function() {
$(".addbutton").click(function() {
$('#mytable tbody>tr:last').clone(true).insertAfter('#mytable tbody>tr:last');
return false;
});
});
</script>
So that works for my table with ID of mytable
. See working JSFiddle here
What I want to do is make the code work for any table on the same page. So I would have multiple add
buttons - and when you press add
it will make the closet table row duplicate.
This is what I tried to guess - but it doesnt work
<script>
$(document).ready(function() {
$(".addbutton").click(function() {
$(this).closest('table tbody>tr:last').clone(true).insertAfter($(this).closest('table tbody>tr:last'));
return false;
});
});
</script>
How do I make the code work for multiple tables on the same page? JSFiddle of what I currently have that does not work...