JavaScript Select all checkboxes in closest div

I've been trying to get this to work from other posts, but keep running into a wall.

I have an "All" button, that I'd like select all or unselect all in the closest div class of "apply_all"

I'm trying to make this work with a long set of appended divs

        $(document).on('change', '.applyallsearches', (function() {
      		var applyallchecks = $(this).closest('.applyall');
          if (this.checked) {
           applyallchecks.find('input:checkbox').attr('checked'); 
          } else { 
           applyallchecks.find('input:checkbox').removeAttr('checked');
          }
      })
    );
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="pet_selection">    
Select pets<BR>
    <div>
      <input type="checkbox" class="applyallsearches" value="all">All
    </div>
    <div class="applyall">
      <input type="checkbox" name="apply_all" value="1">Pet 1<BR>
      <input type="checkbox" name="apply_all" value="2">Pet 2<BR>
      <input type="checkbox" name="apply_all" value="3">Pet 3<BR>
      <input type="checkbox" name="apply_all" value="4">Pet 4<BR>
      <input type="checkbox" name="apply_all" value="5">Pet 5<BR>
      <input type="checkbox" name="apply_all" value="6">Pet 6<BR>
      <input type="checkbox" name="apply_all" value="7">Pet 7<BR>
      <input type="checkbox" name="apply_all" value="8">Pet 8<BR>
    </div>
    
    <BR>Select pets<BR>
    <div>
      <input type="checkbox" class="applyallsearches" value="all">All
    </div>
    <div class="applyall">
      <input type="checkbox" name="apply_all" value="1">Pet 1<BR>
      <input type="checkbox" name="apply_all" value="2">Pet 2<BR>
      <input type="checkbox" name="apply_all" value="3">Pet 3<BR>
      <input type="checkbox" name="apply_all" value="4">Pet 4<BR>
      <input type="checkbox" name="apply_all" value="5">Pet 5<BR>
      <input type="checkbox" name="apply_all" value="6">Pet 6<BR>
      <input type="checkbox" name="apply_all" value="7">Pet 7<BR>
      <input type="checkbox" name="apply_all" value="8">Pet 8<BR>
    </div>
    
    <BR>Select pets<BR>
    <div>
      <input type="checkbox" class="applyallsearches" value="all">All
    </div>
    <div class="applyall">
      <input type="checkbox" name="apply_all" value="1">Pet 1<BR>
      <input type="checkbox" name="apply_all" value="2">Pet 2<BR>
      <input type="checkbox" name="apply_all" value="3">Pet 3<BR>
      <input type="checkbox" name="apply_all" value="4">Pet 4<BR>
      <input type="checkbox" name="apply_all" value="5">Pet 5<BR>
      <input type="checkbox" name="apply_all" value="6">Pet 6<BR>
      <input type="checkbox" name="apply_all" value="7">Pet 7<BR>
      <input type="checkbox" name="apply_all" value="8">Pet 8<BR>
    </div>
</div>
Answer:1

Here you go: (this will work even for appended divs also)

$(document).on('change', '.applyallsearches', function() {
          var applyallchecks = $(this).parents('.search-sec').find('[name="apply_all"]');
          if (this.checked) {
           applyallchecks.prop('checked','checked'); 
          } else { 
           applyallchecks.removeAttr('checked');
          }
      })
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
Select pets<BR>
  <div class="search-sec">
    <div>
      <input type="checkbox" class="applyallsearches" value="all">All
    </div>
    <div class="applyall">
      <input type="checkbox" name="apply_all" value="1">Pet 1<BR>
      <input type="checkbox" name="apply_all" value="2">Pet 2<BR>
      <input type="checkbox" name="apply_all" value="3">Pet 3<BR>
      <input type="checkbox" name="apply_all" value="4">Pet 4<BR>
      <input type="checkbox" name="apply_all" value="5">Pet 5<BR>
      <input type="checkbox" name="apply_all" value="6">Pet 6<BR>
      <input type="checkbox" name="apply_all" value="7">Pet 7<BR>
      <input type="checkbox" name="apply_all" value="8">Pet 8<BR>
    </div>
  </div>
    
    <BR>Select pets<BR>
    <div class="search-sec">
      <div>
        <input type="checkbox" class="applyallsearches" value="all">All
      </div>
      <div class="applyall">
        <input type="checkbox" name="apply_all" value="1">Pet 1<BR>
        <input type="checkbox" name="apply_all" value="2">Pet 2<BR>
        <input type="checkbox" name="apply_all" value="3">Pet 3<BR>
        <input type="checkbox" name="apply_all" value="4">Pet 4<BR>
        <input type="checkbox" name="apply_all" value="5">Pet 5<BR>
        <input type="checkbox" name="apply_all" value="6">Pet 6<BR>
        <input type="checkbox" name="apply_all" value="7">Pet 7<BR>
        <input type="checkbox" name="apply_all" value="8">Pet 8<BR>
      </div>
    </div>
    
    <BR>Select pets<BR>
    <div class="search-sec">
      <div>
        <input type="checkbox" class="applyallsearches" value="all">All
      </div>
      <div class="applyall">
        <input type="checkbox" name="apply_all" value="1">Pet 1<BR>
        <input type="checkbox" name="apply_all" value="2">Pet 2<BR>
        <input type="checkbox" name="apply_all" value="3">Pet 3<BR>
        <input type="checkbox" name="apply_all" value="4">Pet 4<BR>
        <input type="checkbox" name="apply_all" value="5">Pet 5<BR>
        <input type="checkbox" name="apply_all" value="6">Pet 6<BR>
        <input type="checkbox" name="apply_all" value="7">Pet 7<BR>
        <input type="checkbox" name="apply_all" value="8">Pet 8<BR>
      </div>
    </div>
Answer:2

I just started with typescript and trying to create an instance to the typescript class but I am unsuccessful. Below are my files App.ts import { EventEmitter } from 'events'; interface Emitter ...

I just started with typescript and trying to create an instance to the typescript class but I am unsuccessful. Below are my files App.ts import { EventEmitter } from 'events'; interface Emitter ...

  1. typescript typeerror illegal constructor
  2. typescript typeerror not a constructor

I am trying to make this: 3 input boxes take the value of the input and compare to a certain percentage if values are within 3% of each other. output = something else output something else. any ...

I am trying to make this: 3 input boxes take the value of the input and compare to a certain percentage if values are within 3% of each other. output = something else output something else. any ...

  1. compare values within list python
  2. compare values within dictionary python
  3. compare values in excel
  4. compare values in two columns excel
  5. compare values in dictionary python
  6. compare values in array javascript
  7. compare values in same dictionary python
  8. compare values in two columns
  9. compare values in list python
  10. compare values in two dataframes pandas
  11. compare values in javascript
  12. compare values in sql
  13. compare values in two lists python
  14. compare values in two columns pandas
  15. compare values in two arrays javascript
  16. compare values in r
  17. compare values in python
  18. compare values in excel columns
  19. compare values in two sheets excel
  20. compare values in array

I'm currently working on developing some set of codes to display all blobs inside specified Azure Container using web front-end. I'm expecting the final output to be something like this: I started by ...

I'm currently working on developing some set of codes to display all blobs inside specified Azure Container using web front-end. I'm expecting the final output to be something like this: I started by ...

I want to block my UI and show a spinner while it is blocked. I tried to use the following : blockUI.start("<div class='dots-loader'>Minions are Working!</div>"); // some code ...

I want to block my UI and show a spinner while it is blocked. I tried to use the following : blockUI.start("<div class='dots-loader'>Minions are Working!</div>"); // some code ...