nickf nickf - 6 months ago 7
Javascript Question

Convert a jQuery set into HTML

Given a jQuery result set, how do you convert that back into plain HTML?

<div class="abc">
foo <strong>FOO</strong>
</div>
<div class="def">
bar
</div>


--

var $mySet = $('div');


Given
$mySet
, how would you go about returning to the plain HTML above?

Answer

If your set consists of precisely one item, you can use ye olde Javascript:

var html = $mySet[0].outerHTML; // note HTML is all caps... that always burns me
Comments