Reputation: 967
Is it possible to add hidden variables to a HTML table row? Which can be accessed when processing each row in jQuery?
Thanks
Upvotes: 1
Views: 3322
Reputation: 191
you can add as row id,
<tr id="your value"><td></td></tr>
or on jquery
<tr data-somedata="your value"><td></td></tr>
can use
$(this).data('somedata')
or you can make
<td class="hide"> your value</td>
and do some css like this
.hide{
display:none;
}
Upvotes: 6
Reputation: 1131
addstyle="display:none;"
in which data you want to hide i.e tr
or td
and you can access while processing each row
Also you can add some class
i.e. attr
class="className"
and add CSS
.className{
display:none;
}
Upvotes: 0
Reputation: 665
One way of binding data to html element is using data-atrribute, like <tr data-employee="{emp_id:100,emp_name:John}"><td>....</td></tr>
later you can get or set the attribute using $(tr).attr('data-employee') // Get The Data
$(tr).attr('data-employee',varEmployeeData) // Set the Employee Data
You can also use Jquery .data method.
Upvotes: 0
Reputation: 586
Like
<table>
<tr id="theTargetRow" data-id="2">
<td>My Name</td>
</tr>
</table>
and can be retrieved by
<script>
$(document).ready( function() {
$('#theTargetRow').data('id') // 2
})
</script>
Upvotes: 0