Wednesday 25 December 2019

javascript - How to select a button and delete a grandparent div of that button when the button is clicked?



This here is my code.



    $(document).ready(function(){
$(".btn.btn-default.btn-lg.remove").click(function(){
$(this).parent().remove();
});
});





      













I want the entire div to get deleted when the button of class="btn btn-default btn-lg remove" gets clicked. I cant use id because i am dynamically appending the above div using append jquery.


Answer



You can use closest




$(document).ready(function(){
$(".btn.btn-default.btn-lg.remove").click(function(){
$(this).closest('.row').remove();
});
});

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...