var $delButton = $('<div/>', {id: "delete-images"}).click(function() { deleteImages(obj); }); $(this).find('img').before($delButton);