confusing code
confusing code
Hi folks,
New user here. I'm going through "JQuery in Action" and am having a little trouble understanding how to read a piece of code:
-
$(function(){
$('fieldset div div').hide();
$(':checkbox').click(function(){
var checked = this.checked;
$('div',$(this).parents('div:first'))
.css('display',checked ? 'block':'none');
$('input[type=text]',$(this).parents('div:first'))
.attr('disabled',!checked)
etc.
Specifically I don't understand this line : .attr('disabled',!checked)
What it does is to set input[type=text] to "disabled" when the checkbox is unchecked. But this doesn't make sense to me. I thought the value here had to be a Boolean - in which case the code would set the "disabled" attribute to "false". Instead it says "Set the text input to disabled WHEN the checkbox is not checked."
It's just confusing is all. If it's supposed to be a Boolean, how can it be conditional like that?