mercredi 16 décembre 2015

checkbox that checks other checkboxes

I know there is multiple questions about this, but I have a different problem here, I have an accordion menu inside of another accordion menu, and there is checkboxes on each title, here is a simplified fiddle where the problem is quite obvious: I want the last checkbox to check all the other ones, including the ones inside the accordion

Simplified code (without the accordion which is useless in my issue):

<form>
  <label><input type="checkbox" class="btn1" checked />importTitle</label>
  <label><input type="checkbox" id="selectall" class="btn1"/> Import all 
positions</label>

  <div id="checkboxlist">
    <label><input type="checkbox" class="btn" checked/>Import a</label><br />
    <label><input type="checkbox" class="btn" checked/>Import b</label><br />
    <label><input type="checkbox" class="btn" checked/>Import c</label><br />
    <label><input type="checkbox" class="btn" checked/>Import d</label><br />
  </div>
  <label><input type="checkbox" class="btn1" checked /> Import Link</label>
  <label><input type="checkbox" class="btn1" id="selectAll"/>Import everything</label>
</form>

and the js:

$('#selectall').click(function() {
  $(this.form.elements).filter('.btn').prop('checked', this.checked);
});
$('#selectAll').click(function() {
  $(this.form.elements).filter('.btn1').prop('checked', this.checked);
});




Aucun commentaire:

Enregistrer un commentaire