I have the html like below:
<table class="table" id="subscriptions">
<tbody id="subscriptions-tbody">
<tr>
<td>Item 1</td>
<td><a href="#">delete</a></td>
</tr>
<tr>
<td>Item 2</td>
<td><a href="#">delete</a></td>
</tr>
<tr>
<td>Item 3</td>
<td><a href="#">delete</a></td>
</tr>
</tbody>
</table>
Items can be added dynamically there.
Now, I should create the function, which will help me to delete the element from the list, if user clicks delete.
Looks like I should:
- assign some unique id for each item in the list (I have such ids) – where should I keep them? part as
href?; - once user clicks on the link, I should prevent default action and pass control to my function (it will hide the element from the list and will sent POST request to the server) with item id as parameter.
How to do it?
You should keep the information required for the server side (like the
id) on thetrwithdata-attributes, and use.on()to handle the events from the table..html
script