Skip to main content
deleted 8 characters in body
Source Link
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 exampleExample

$('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>

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>

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

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>

deleted 95 characters in body
Source Link
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

Using .is(':checked') method and a conditional statement to change the background-color

$('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>

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

Working example

Using .is(':checked') method and a conditional statement to change the background-color

$('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>

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>

added 18 characters in body
Source Link
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

Using element.is(':checked') method and a conditional statement to change the background-color

$('input').on('click', function(){ is_checkedisChecked = $(this).is(':checked') if(is_checkedisChecked){ $('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>

Working example

Using element.is(':checked') method to change the background-color

$('input').on('click', function(){ is_checked = $(this).is(':checked') if(is_checked){ $('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>

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

Working example

Using .is(':checked') method and a conditional statement to change the background-color

$('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>

added 18 characters in body
Source Link
Gass
  • 9.6k
  • 5
  • 47
  • 53
Loading
deleted 1 character in body
Source Link
Gass
  • 9.6k
  • 5
  • 47
  • 53
Loading
added 4 characters in body
Source Link
Gass
  • 9.6k
  • 5
  • 47
  • 53
Loading
Source Link
Gass
  • 9.6k
  • 5
  • 47
  • 53
Loading