Check out the fiddle below:
https://jsfiddle.net/shaswatatripathy/enq0kfqL/2/
I need help with creating a remove function and adding a CSS class to a clicked row.
1. When I click on "remove", the clicked row should be deleted.
When I click on a row, it should be highlighted with a 'highlightRow' CSS class
I also need to check if there are any rows in the table and store that information in a variable
Only one row at a time should be highlighted in red (clicked row). If no row is selected, the remove button should not be visible
HTML
col1header | col2header |
---|
CSS
.visibilityHide {
visibility: hidden;
}
.highlightRow{
color:red;
}
table {
border-collapse: collapse;
}
table, th, td {
border: 1px solid black;
}
JS or Jquery
function add() {
var addRow1;
var addRow2;
addRow1 = "<tr onclick="+"getdetails(this)"+"><td>" + "col1valuerow1" + "</td><td>" + "col2valuerow1" + "</td></tr>";
addRow2 = "<tr onclick="+"getdetails(this)"+"><td>" + "col1valuerow2" + "</td><td>" + "col2valuerow2" + "</td></tr>";
$("#myTableid tbody").append(addRow1);
$("#myTableid tbody").append(addRow2);
}
function remove() {
}
function getdetails(row) {
$('#removerow').css('visibility', 'visible');
}