My problem is rather hard to word. So I have created a jsfiddle.net of my issue.
I have a list of divs. Inside each div there is some text and an "X". The "X" is to delete the parent div. The three divs and "X" works fine. But if I were to add a button that appends a new div to the list, then those "X"'s don't work. Any idea what this problem is? I know this is probably some basic JS DOM thing. But I'm self thought and just don't understand JS very well to resolve this issue.
Please and thank you for your time.
$("#trigger").click(function() {
$("#participants_wrapper").append("<div class='participant'><a href='javascript:void(0)' class='delete_participant'>X</a>Appended</div>");
return false;
});
$(".delete_participant").click(function(){
$(this).closest('div').remove();
});
<div id="participants_wrapper">
<div class="participant"><a href="javascript:void(0)" class="delete_participant">X</a>already here</div>
<div class="participant"><a href="javascript:void(0)" class="delete_participant">X</a>already here</div>
<div class="participant"><a href="javascript:void(0)" class="delete_participant">X</a>already here</div>
</div>
<a href="javascript:void(0)" id="trigger">add this participant</a>