I have a jQuery object (named wid) that has a code similar to this:
<li class='widget'>
<div class='widget-head'>
<h3>head</h3></div>
<div class='widget-content'>
<p>LINE1</p>
<p>LINE2</p>
</div>
</li>
I want to append <p>LINE3</p> after the last line of the content. Currently I’m doing this:
var content = $('.widget-content');
var $newItem = $('<p>LINE3</p>').appendTo($(content).last(), wid);
but the problem is that it appends the line to the last line of the last gadget (not wid). How can I make it append to the last line of the wid and not the last widget?
You missplaced context – it should be in
contentquery. Also, you dont have to wrap again content into jq object, and assuming you have only one content in widget, you dont have to uselast.