jQuery closest() remove() on <a> doesn't work?

2 replies
Please see this page which has this code:

Code:
<div class="pure-control-group query-brand-by-column">
    <!-- somethings else -->
    <div class="pure-u-1 pure-u-sm-1-24 control-group-sub">
        <a href="javascript:$(this).closest('.query-brand-by-column').remove();" class="pure-button danger">X</a>
    </div>
</div>
Clicking the X link should remove its ancestor div.query-brand-by-column as a whole but somehow it's not working. I've checked jQuery docs and this answer and the code seems absolutely all right to me but it simply doesn't work. Any idea?
#&lta&gt #<a> #closest #jquery #remove #work
  • Profile picture of the author anuislam
    Please see this following instruction i hope it's very helpful for you.

    Thank you

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
    </head>
    <body>
    <div class="pure-control-group query-brand-by-column">
    <!-- somethings else -->
    <div class="pure-u-1 pure-u-sm-1-24 control-group-sub">
    <a href="#" id="your_id_name" class="pure-button danger">X</a>
    </div>
    <script>
    $(document).ready(function(){
    $('#your_id_name').on('click', function(e){
    e.preventDefault();
    $(this).closest('.query-brand-by-column').remove();
    });
    });
    </script>
    </div>
    </body>
    </html>
    {{ DiscussionBoard.errors[10957442].message }}

Trending Topics