Luke Prior
Luke Prior

Reputation: 967

Add hidden data to HTML table

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

Answers (4)

Khagesh
Khagesh

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

Sushil
Sushil

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

Ayan_84
Ayan_84

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

David Bray
David Bray

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

Related Questions