Best way to assign a javascript object to html element

html, javascript, object

Solution

If use JQuery you could use the data storrage functionallity

See data documentation of JQuery

//To store value or obj:
$("#myDivId").data("myKey", valueVar);
//Later to load:
var fetchValue = $("#myDivId").data("myKey");

Problem

I'm getting a javascript object via ajax. I need to attach this object to a div in order to be recovered later, for example, on a click event. If instead of an object I had a variable I would push it into the html tags like this: ``` '<div variable="'+value+'"></div>'; ``` And I would recover its value like this: ``` var value= $(this).attr('variable') ``` Could you suggest me a good approach to do that with objects? Thank you very much!

Original source