Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

on click remove parent div

Tags:

html

jquery

i am trying to remove a div on click on a link . the problem is there are multiple structure of same div and link and i tried making a function but it removes all div's

$(document).on("click", ".fd-bxx-cls", function(e) {
  e.preventdefault;
  $(this).parents('.fd-box2').fadeOut(300);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="fd-box2">
  <div class="fd-box3">
    <a href="#" class="fd-bxx-cls"></a>
    <a class="fd-avtar-s" href="#"><img src="images/avatr_s.png" /></a>
    <div class="fd-nme-info">
      <span class="fd-mn-ttl">Robert Porter</span>
      <span class="fd-mncn-ttl">Pheonix, AZ</span>
    </div>
    <a href="#" class="ep-btns fd-msg-btn"></a>
  </div>
</div>
like image 550
Param Veer Avatar asked Mar 06 '26 06:03

Param Veer


1 Answers

Fading out the grandparent should work.

$(this).parent().parent().fadeOut(300);

Another possibility is using .closest().

$(this).closest(".fd-box2").fadeOut(300);
like image 162
Alexander Avatar answered Mar 08 '26 20:03

Alexander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!