jquery - JavaScript Check box with collapse button -


i want make below code works check box collapse button.

<label>     <input type="checkbox" id="postageyes" name="postage1" value="yes" />yes</label> <div id="conditional1">     <p>this should show when 'yes' checkbox &lt;input&gt; element checked.</p>     <a href="">close</a> </div> 

javascript

var conditionalcontent1 = $('#conditional1'), group = $('input[type=checkbox][name=postage1]');  group.change(function() {    conditionalcontent1.toggle(group.filter(':checked').val() === 'yes'); }).change(); 

when checked check box new div open, want done is. when click close link, open div close , unchecked checked box.how this. can help?

you can use change event on checkbox. , toggle hide/show div.

$('#postageyes').on('change', function() {     $('#conditional1').toggle($(this).is(':checked')); });  $('#conditional1').on('click', 'a', function() {     $('#postageyes').prop('checked', false);     $('#conditional1').hide();     return false; }); 

demo: http://jsfiddle.net/tusharj/n7044syx/1/


Comments