I have the following code:
$(this).children(\"a:eq(0)\").append(\'
You can use the :last-child selector to find the last appended element, then you can remove it:
$('img:last-child', this).remove(); // get the last img element of the childs of 'this'