Is it possible to call an html class with specific id, because for now I have same functionality in my class then I need to pull it through class + id to be specific.
I have button that populates data to my table:
<button type="button" onclick="loadData()">Get Data</button>
and I have two tables with the same class name:
<table class="sortable" id="1">
<thead>
<tr>
<th>Last Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<table class="sortable" id="2">
<thead>
<tr>
<th>First Name</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
</tr>
</tbody>
</table>
My aim is to update only the first table which has the id of 1. because right now when I clicked the button both of them will update since they have the same class name. Is it possible if they can Identify by class name + id?
here is my update:
function loadData() {
$.ajax({
url: '/Home/ReadDB',
type: 'GET',
dataType: 'json',
success: function (data) {
var row = '';
$.each(data, function (i, item) {
row += '<tr><td>' + item.LName + '</td><td>' + item.age
+ '</td><td>' + '<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModal"> Add </button >' + '</td></tr>';
});
console.log(row)
$('.sortable tbody').html(row); // --This one overrides my previous result and want to identify by id
},
error: function (jqXhr, textStatus, errorThrown) {
alert(errorThrown);
}
});
}