When I check a checkbox, I want it to turn <p> #0099ff.
When I uncheck the checkbox, I want it to undo that.
Code I have so far:
$('#checkbox').click(function(){
if ($('#checkbox').attr('checked')) {
/* NOT SURE WHAT TO DO HERE */
}
})
I would use
.change()andthis.checked:—
On using
this.checkedAndy E has done a great write-up on how we tend to overuse jQuery: Utilizing the awesome power of jQuery to access properties of an element. The article specifically treats the use of
.attr("id")but in the case that#checkboxis an<input type="checkbox" />element the issue is the same for$(...).attr('checked')(or even$(...).is(':checked')) vs.this.checked.