In jQuery I can create a HTML element with data:
$(\'\').data(\"field\", { i: i, j: j }).appendTo(\"body\");
<
If you want the html of a button which will have the same data available as the button you created, you'll have to use the html5 data attributes. i.e.
and read it
function btn(){
var field = $('button').data("field");
alert(field.i)}
}
with plain js
function btn(){
var field = JSON.parse(document.querySelector('button').getAttribute("data-field"));
alert(field.i)}
}