I need to a a trigger to a dynamically created element then use event deligation to pick up the event and remove the dynamic element.
<div class="row">
<div class="col-md-8 clickable"></div>
<div class="col-md-4 display-clicks">
<ul class="clicks">
</ul>
</div>
</div>
so lets say we have the above html within the display-clicks div the ul is appended with a list of co-ordinates clicked in the clickable div and next to each a remove button. the clickable div is populated with dynamically created spans all of which have a unique Id which is just the concatenated co-ordinates of the click. I can remove the appended li containing the co-ordinates and button using:
$('.display-clicks').on('click','button',function(){
// and this gets me the id of the dynamic span to be removed
// from the clickable div
var id = $(this).data('span-id');
// this wont work
$(id+'_span').remove();
// neither will this
$(id+'_span').trigger('myEvent');
$(this).parent().remove();
console.log(id);
})
myEvent looks like this
$('.clickable').on('myEvent', 'span', function(event){
$(this).remove();
})
Any ideas?
$('clickable') => $('.clickable')htmllooks like?<span id="439.124_span">x</span>