Checkbox toggling with jQuery
<input id="mycheckbox" name="mycheckbox" type="checkbox" value="Y" />My Checkbox - click to toggle
<div id="mydiv" style="display:none;">This is a div that's to be shown/hidden.</div>
$('#mycheckbox').change(function(){ $("#mydiv").slideToggle('slow'); }); if($('#mycheckbox').is(':checked')){ $("#mydiv").slideToggle('slow'); };Here "mycheckbox" is the checkbox id and "mydiv" is the id of div that you want shown/hidden when toggling the checkbox.
See example below:
My Checkbox - click to toggle
what if i want it reverse?
ReplyDeleteshow the div when uncheck?
please help!
@Nhoel: Then you'd just remove "display:none" from the CSS. This will initially show the content and selecting the checkbox will hide it. Hope this helps.
DeleteExactly was I were looking for ... basic and simple jQuery! Thanks mate :-)
ReplyDelete