I want to add new row when the button is clicked. Below is my code.
<div class="table">
<div id="rows" class="row">
<div id="col1" class="p2">
<asp:CheckBox id="checkbox1" runat="server" Text="" TextAlign="Right" />
</div>
<div id="col2" class="p3"> </div>
<div id="col3" class="p4">
<asp:TextBox ID="TextBox2" runat="server" Text="2.00"/>
</div>
<div id="col4"class="p5"> </div>
<div id="col5" class="p6">
<asp:TextBox ID="TextBox3" runat="server" Text="1.00"/>
</div>
<div class="row2" style="text-align:center;">
<button class="clsButton" id="addrow">Add Row</button>
</div>
</div>
below is my jQuery code:
var cloneCount = 1;
//add new row
$("#addrow").click(function () {
$('#rows')
.clone(true)
.attr('id', 'rows' + cloneCount++, 'class', 'row')
.insertAfter('[id^=rows]:last');
return false;
});
The button does not seems to be working. Which part was wrong? I'm really new in JavaScript. Im using VisualStudio 2012, in .aspx form and C# language. Thanks for helping!
document.getElementById("checkbox3");even it's not available in youe snippet.row1 = row.cloneNode(true);and thendocument.getElementById('table').append(row1);But this will lead you to duplicate the IDs. So use classes instead.