Skip to main content
6 of 7
deleted 95 characters in body
Gass
  • 9.6k
  • 5
  • 47
  • 53

You can use the .is(':checked') method which returns true if an element is checked, otherwise it returns false.

Working example

$('input').on('click', function(){ isChecked = $(this).is(':checked') if(isChecked){ $('html').css('background-color','green') } else{ $('html').removeAttr('style') } })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <label><input type="checkbox"> Try me </label>

Gass
  • 9.6k
  • 5
  • 47
  • 53