I have a dynamic table where a button on click adds a new row. I want to add a name attribute each time new row created.
Here's my code:
$(function() {
const $tb = $('#service-table tbody');
$("tr",$tb).eq(0).hide();
$("#serviceAdd").on("click",function() {
const $row = $tb.find("tr").eq(0).clone();
$row.show();
$row.find("select").val("").attr("name", "service_id[]"); // reset the select
$row.find(".s_qty").val().attr("name", "s_qty[]"); // reset the numbers
$row.find(".s_total").val().attr("name", "s_total[]"); // reset the numbers
$tb.append($row);
});
});
It shows error Uncaught TypeError: $row.find(...).val(...).attr is not a function
I have tried with many changes but it shows the same error.
How can I add attribute to new rows?