Reputation: 3309
In most of my apps, I need to store ID on data attributes to perform CRUD operations on specific elements of the DOM.
Indeed, my elements don't necessarily match specific criteria, or share multiple criteria, so the only way I have to delete them (for example when users clicks on it) is to store their ID in a data-id
attribute and then send it to my server.
I use socket.io
a lot.
Is that a good practice?
Upvotes: 0
Views: 76
Reputation: 191749
This is good practice. I don't think there is a better attribute to store this identifying data than data-id
. You need some unique identifier for the document so the server knows which document the user wants to interact with when performing update/delete operations.
As long as your document is properly validated on the server side, i.e. before deleting/updating you check to make sure that the user in the session has authority to perform valid actions, there is no security risk of exposing the document _id
s.
Upvotes: 1