I created a DOM fragment using JQuery:
var $content = $("<div /", {id:"content"})
I want to output the fragment as a string, so I attempted:
$content.html();
That returns an empty string, because there are no children. How can I return a string containing:
<div id="content" />
jQuery doesn’t have anything in its API to do this directly, but you can use the native
.outerHTMLproperty.…but Firefox doesn’t support this, so you can do something like this…
http://jsfiddle.net/m22fn/
Note that a
<div>tag doesn’t self-close.