I'm not sure if this is the best way, but what about this:
var htmlstr = "<div><ul><li>some text 1</li></ul></div><div><ul id=list><li>some text 2</li></ul></div>";
$('body').append('<div id="test" style="display: none;">' + htmlstr + '</div>');
$test = $('#test');
$test.find('ul').append('<li>new</li>');
htmlstr = $test.html();
$test.remove();
var s = $('ul#list', $(htmlstr)).html();
Basically, you embed HTML in the DOM, add a new list item, and then return the resulting HTML code and delete the added items.
source
share