Hi i have a button which add's a div to my html using jquery append(). Now each of the div's appended has a close button which removes the appended div using jquery remove(). The code looks like this:
$(document).ready(function(){
$("#image-btn").click(function(){
var $imageElement = $("<div class='image_element' id='image-element'><div class='image_holder' align='center'><input type='image' src='{{URL::asset('images/close-icon.png')}}' name='closeStory' class='closebtn' id='close-img-btn' width='22px'><button type='button' class='img_btn' id='img-btn'>Upload Image</button></div></div>");
$("#element-holder").append($imageElement);
$imageElement.fadeIn(1000);
$("#close-img-btn").click(function(){
$imageElement.remove();
});
});
});
Now the problem is arises while removing the appended div's. When i add multiple div's (Each has a close button) and click on the close button of the last appended div nothing happens. But clicking on the close button of the first appended div closes all the other appended div.
I am trying to close only the div that i hit close and not the others. How do i do this ? Would really appreciate if someone could guide me through. Thanks.