jQuery show child divs when checkboxes are checked -


i have select input controls display of different sets of checkboxes using jquery. i.e. when select different options displays different divs containing more inputs.

<select type="select" name="set" id="set" required>     <option value="">select</option>     <option value="set1">one</option>     <option value="set2">two</option> </select>  <div id="set1" class="checkboxes">   <input type="checkbox" name="set1-questions1" id="set1-questions1">   <div id="set1-questions1-qs"></div>   ... </div> <div id="set2" class="checkboxes">   ... </div> 

jquery

$('#set').change(function(){   $('.checkboxes').hide();   $('#' + $(this).val()).show(); }); 

this works ok i'd checkboxes within each div control display of sub div. i.e select option select , check checkbox display sub div.

demo full markup , first part working

i don't know how achieve second part. need function link checkboxes corresponding divs , show/hide based on if checked or not?

add change handler checkboxes, , toggle corresponding <div> based on state of checkbox:

$('div.checkboxes input[type="checkbox"]').on('change', function() {    $('#' + this.id + '-qs').toggle( this.checked );  }); 

fiddle


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -