Checkbox is checked then show a div else hide the div

For example, if the fruits checkbox is checked, then I need to show a category , else hide the textbox.

Demo

Orange

HTML

<input type="checkbox" id="fruits" name="fruits" checked>
<label for="fruits">Fruits</label>
<div class="category">Orange</div>

Jquery

$(function(){
    function checked(){
       if($('#fruits').is(':checked')){
          $('.category').show();
          
         }else{
          $('.category').hide();
         } 
       }
        
    $('#fruits').click(function(){
       checked()
    })
})
  • Share
  • Copyright 2016 by WebiBeris.com. All Rights Reserved.