javascript - Toggle show hide div on checkbox value -


hee,

im trying toggle multiple divs based on parent checkbox value.

it doesn't seem work. rookie mistake! can me out?

html:

<li><input class="yourcheckbox" type="checkbox" value="1" /><label>type zaak</label></li>     <div id="1" style="display:none;">                   <label class="marginleft20" for="invtyperegeling">type zaak<strong> *</strong></label>                   <select multiple="multiple">             <option>bezwaar</option>             <option>beroep</option>             <option>administratief beroep</option>             <option>proforma beroep</option>             <option>proforma hoger beroep</option>             <option>hoger beroep-dept. verweerder</option>             <option>hoger beroep-dept. appelland </option>             <option>voorlopige voorziening</option>             <option>rechtstreeks beroep</option>         </select>     </div> 

javascript:

$(document).ready(function(){    $(".yourcheckbox").click(function(){        $("#"+$(this).val()).toggle();    }); ]); 

http://jsfiddle.net/sentah/o1mjxfm6/

a couple of things:

  1. your fiddle wasn't including jquery
  2. your sytax function ended in ] instead of }
  3. your binding on checkbox should .change() instead of .click()

https://jsfiddle.net/o1mjxfm6/18/


Comments