I am dynamic building html table with rows for the users to have the option to remove or add new rows. My code is replacing both A tag onclick event and I wanted to know if there is a way to stop this from happening
var addrow = "<a><span class='btn btn-nccnBlue' onclick=\"AddNewRow(1, 'false')\"><i class='fa fa-plus'></i></span></a>";
var remrow = "<a><span class='btn-red' onclick=\"RemoveRow(1, 'false')\"><i class='fa fa-times'></i></span></a>";
td.innerHTML = addrow + remrow;
function AddNewRow(type) {
debugger;
var tableRef = document.getElementById("example");
var trlength = $('#example tbody tr').length + 1;
var lasttr = $('#example tbody tr:last').clone();
lasttr.find('span').attr('onclick', 'RemoveRow(' + trlength + ')');
lasttr.find('span').attr('onclick', 'AddNewRow(' + trlength + ')');
$('#example tbody').append(lasttr);
}
function RemoveRow(type) {
debugger;
var tableRef = document.getElementById("example");
$("#AssetRow").clone().appendTo(tableRef);
}
In my html code the class btn red should be RemoveRow(4) not AddNewRow(4)
<span class="btn btn-nccnBlue" onclick="AddNewRow(4)"><i class="fa fa-plus"></i></span>
<span class="btn-red" onclick="AddNewRow(4)"><i class="fa fa-times"></i></span>