I'm cloning a row in the table, I can insert a new value into id
, but would like to concatenate a new value to the existing id
.
$("#addRow").click(function() {
$clone = $('#tabela tbody>tr:last')
.clone(true)
.insertAfter('#tabela tbody>tr:last');
$clone.find('input').attr({
'data-id': $('#tabela tbody>tr').length,
'id': $('#tabela tbody>tr').length
});
$clone.find('input').val("");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script><tableid="tabela">
<tbody>
<tr>
<td><input type="text" name="nome-1" id="nome-1" /></td>
<td><input type="text" name="funcao-1" id="funcao-1" /></td>
<td><input type="text" name="setor-1" id="setor-1" /></td>
</tr>
</tbody>
</table>
<button id="addRow">AddRow</button>
With each addition of a new line, id
should be:
nome-2
funcao-2
setor-2
...
nome-10
funcao-10
setor-10