You can use this:
<li class="user" data-user='{"name":"Royi Namir", "city":"Boston", "lang":"js", "food":"Bacon"}'> </li>
And then
var user = JSON.parse(element.dataset.user);
Using jQuery, it is even simpler:
var user = $(element).data('user');
And if you want to get all your users:
var users = $('[data-user]').map(function(){return $(this).data('user')});
There will be less redunduncy and a directly used structure, especially with deeper properties. Data attributes are not just for rows.
But the main thing in data- attributes is the normalization of practice. Now it’s clear that when viewing HTML, which attributes are the standard HTML (view) attributes and which attributes are data (specific to your application logic).
source share