Skip to content

Commit

Permalink
Add new function to format and add rows to a table in the DOM.
Browse files Browse the repository at this point in the history
  • Loading branch information
YasinDehfuli committed Nov 17, 2023
1 parent 8ee7a57 commit 9602bda
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions assets/factor/factor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
function formatRows(main, prefer, common) {
return '<tr><td class="col-xs-3"><input type="text" value="' +main+ '" class="form-control editable" /></td>' +
'<td class="col-xs-3"><input type="text" value="' +common+ '" class="form-control editable" /></td>' +
'<td class="col-xs-3"><input type="text" value="' +prefer+ '" class="form-control editable" /></td>' +

'<td class="col-xs-1 text-center"><a href="#" onClick="deleteRow(this)">' +
'<i class="fa-solid fa-xmark"></i></a></td></tr>';
};

function deleteRow(trash) {
$(trash).closest('tr').remove();
};

function addRow() {
var main = $('.addMain').val();
var preferred = $('.addPrefer').val();
var common = $('.addCommon').val();
$(formatRows(main,preferred,common)).insertAfter('#addRow');
$(input).val('');
}

$('.addBtn').click(function() {
addRow();
});


0 comments on commit 9602bda

Please sign in to comment.