Since id is unique you need to use class instead for your div
.
<div class="remove"><a class="button" href="#"><span class="search-icon">remove</span></a></div>
Also, because your div
are dynamically generated so all the events will not be available for these elements. In this case you can use event delegation:
Event delegation allows us to attach a single event listener, to a parent element, that will fire for all children matching a selector, whether those children exist now or are added in the future.
$('body').on('click', '.remove' , function(){
$(this).closest('.draggable').remove();
});
So basically, this technique will help you to attach click handler to these newly added .remove
div elements in your case.