Причина, по которой это не работает должным образом, заключается в том, что вы каждый раз создаете новый объект jQuery.
var theDiv = '<div></div>';
$(theDiv).append('<p>test</p>'); //Create a new jquery object and append a p
alert($(theDiv).html()); //create a new jquery object of just a div and output the html
Если вы хотите решить эту проблему, вам просто нужно создать новую переменную для храненияваш объект jQuery.
var theDiv = '<div></div>';
var $d = $(theDiv).append('<p>test</p>'); //create a new jQuery object and than append
//a p and store it in a variable
alert($d.html()); //output the contents of the variable's html
Пример кода на jsfiddle .