Most of the HTML in my web app is dynamically generated: I take an object and create a grid row for instance, something like this:
var TheHTML = TheHTML + '<div class="HiddenDiv">' + SomeObject.ID + '</div>';
TheHTML = TheHTML + ....
$('#SomeTableContainer').html(TheHTML);
That way, when the user clicks on that row, I can access the ID of the object represented on the row using .find('.HiddenDiv')
How can I instead use .data() to insert the ID of the object to the row and later retrieve it without reading the ID from the DOM?
Thanks.
$(TheHTML).data('ID', SomeObject.ID);ThenHTML += '<div ....>';instead of repeating the Variable after the equal sign. Of course that means you should also drop thevardeclaration.