Let’s say I have an array of Customer structures and I need to generate HTML from it.
Currently I do something like this:
jQuery.each(customers, function(index, item) {
html =+ "<tr custID='" + item.ID + "'><td>" + item.Name + "</td><td>" + item.City + "</td></tr>";
});
The issue here is that I manually add the custID attribute.
I believe the cool way to do this would be using jQuery’s Data function.
But how would I use it in this scenario?
The elegant way is not to append those html tags as if they are text, but create element using
you can modify its attributes and then append it to the html file.
Read more here:
jQuery document.createElement equivalent?