jQuery's :checked not working?

javascript, jquery

Solution

Use .prop() also use the checked state to set the value

$('#check').change(function () {
    $('#colour').prop('disabled', !this.checked);
});

Demo: Fiddle

Problem

So I'm trying to disable a text field if a checkbox isn't selected however its not working as it should. Example: http://jsfiddle.net/GV7U9/ ``` <input type="checkbox" id="check" checked /><br /> #<input type="text" size="8" maxlength="6" id="colour" placeholder="ffffff" /> <script> $('#check').change(function(){ if( $('#check:checked') ){ $('#colour').removeAttr('disabled'); } else { $('#colour').attr('disabled',''); } }); </script> ``` That is a short example of what I'm trying to do but it doesn't want to work. There are no errors in the console. Could someone please explain why this isn't working?

Original source