I am trying to use jQuery to build up some HTML, for which I would like to later get the HTML string. One of the things I am adding is some background data(), which I believe translates to the data-* attributes of the element. Here is an example:
var test = $("<div></div>");
test.data("foo", "bar");
var test2 = $("<div></div>");
test.text("blah");
test2.append(test);
console.log(test2.html());
Unfortunately, when I output the HTML to the log, I get this:
<div>blah</div>
but not the "foo" data. Is there an API call that will output the HTML for a jQuery object, including any data that has been set in it?