Say I have a table of items and I want to add to every row a button to delete that item. Items come from a database, so they have an unique ID. In the jQuery function I have to retrieve the ID of said item so that I can open a confirm box and eventually redirect the browser to the delete page (nevermind security checks, it's for internal use).
Where in the markup is it better to place the ID?
I think it's better to place an id as a part of row's id:
....
<tr id="item_3">...<td>delete tag</td></tr>
<tr id="item_4">...<td>delete tag</td></tr>
<tr id="item_5">...<td>delete tag</td></tr>
....
And then in jQuery get an id using simple regex.
Update:
Or, just put it into rel
attribute of a delete button/anchor.
Update 2:
Since regex may slow down jQuery performance in this case, try to put id's as rel
attribute of each row.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With