Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to jQuery .data()?

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?

like image 924
thebossman Avatar asked Aug 23 '26 14:08

thebossman


1 Answers

data-* attributes. See Can I just make up attributes on my HTML tags?.

like image 129
Ms2ger Avatar answered Aug 26 '26 04:08

Ms2ger