Reputation: 462
I have a table that shows contacts informations. Each row is a different contact. I'm using JQuery to fire an event when I click some fields of the row. My problem is I need to keep trace of the contact's id but I don't want to show it in a column. So I need each row to be associated to the contact id that it holds without showing it on the screen (like an hidden field).
So what is the best solution to keep trace of that id?
Upvotes: 1
Views: 1716
Reputation: 311536
If this is HTML5, use data attributes:
<tr data-user-id="2467">...</tr>
If it's not, then a common convention is to overload the id
attribute:
<tr id="user_2467">...</tr>
Note: you can't do <tr id="2467">
because that's not legal in HTML 4:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
Upvotes: 4
Reputation: 1828
The best solution is a data
attribute. These are valid in HTML5 and can be read using JQuery's data
function or the standard attr
function.
<tr data-id="345678">
Upvotes: 1