I'm a big fan of jQuery's .data() method, but I can't always use it. Often times I am rendering html templates that I pass via AJAX and I need to attach metadata to each of the elements in the template. For example:
<ul>
{% for item in itemlist %}
<li metadata="{{ item.metadata }}">{{ item.name }}</li>
{% endfor %}
</ul>
I know attaching attributes to store data is bad practice (and it might not even work in older versions of IE). What is the best practice? Is there a good alternative to this method?
data-* attributes. See Can I just make up attributes on my HTML tags?.
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