0

I'm trying to remove the class from my .hide elements by clicking on a link. The div that needs to be affect are only the one in the parent <div class="row">.

This is what I've tried - Note, that I've more than one block like this.

$('a[data-action="show-more"]').click(function(e) {
  e.preventDefault();
  $(this).closest('.row').each('.hide').removeClass('hide');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="row">
  <div class="col-lg-12 mb-4">
    <div class="col-lg-4 hide"></div>
    <div class="col-lg-4 hide"></div>
    <div class="col-lg-4 hide"></div>
  </div>
  <div class="col-lg-12 mb-4">
    <a href="#" data-action="show-more">Remove hide class</a>
  </div>
</div>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
Maman
  • 97
  • 6

1 Answers1

3

Close. .each() is for creating a callback function that will iterate over the results. To simply find matching descendants and provide the results to the next chained jQuery function, use .find():

$(this).closest('.row').find('.hide').removeClass('hide');
David
  • 208,112
  • 36
  • 198
  • 279