JQuery: how to return an added item
You can create an element regardless of append by passing the html string to the jQuery function:
$('<div class="test"></div>'); You can use this either in append
$(selector).append(/* $div = */$('<div class="test"></div>').… ); or appendTo
/* $div = */$('<div class="test"></div>').appendTo(selector).… ; or you just divide them into two statements.
That might work too.
<div class="inner">hellworld</div> $('.inner').append('<p>paragraph</p>'); this inserts two new s and existing as the last three child nodes of the body
var $newdiv1 = $('<div id="object1"/>'), newdiv2 = document.createElement('div'), existingdiv1 = document.getElementById('foo'); $('body').append($newdiv1, [newdiv2, existingdiv1]);