I have some data that I need to associate with a specific element, such as a single row in a table. This data contains information, such as the current state, and a unique identifier that correlates with the SQL string. When a user interacts with an element, I want to read a unique identifier and with this identifier, issue an AJAX request so that the user can change the state of this element.
After research, it seems that there are two camps on how to embed this information pertaining to a particular element.
1) Using the data attribute in html5. I understand that this will work in modern web browsers, as well as in older browsers that do not support html5. But while this works, it does not comply with the HMTL specification (less than HTML5), and therefore it will not be checked if you run it using HTML syntax checking.
2) Store additional data in javascript array, object, etc. You need additional work with this now to correlate javascript data with the html element.
What are the pros and cons of using these two different approaches to data storage? And what approach would you recommend?
Thanks!
source share