Here is my code, I have two checkboxes and want to keep one disabled until the other one is enabled:
$(function(){
$('#remember').live('click', function(event){
if($('#remember').is(':checked')){
$('#keepIn').removeAttr('disabled');
}
else
$('#keepIn').attr('disabled', 'disabled');
});
});
The problem is that this function executes before the default action and when I click in the first one $('#remember').is(':checked') returns false (the old value) instead of true.
You can use
changeevent instead:DEMO: http://jsfiddle.net/jP3NY/
NB:
livemethod is deprecated. You should better useonordelegate.For the newer version of jQuery the solution could be as follows:
Instead of
bodyyou can use any parent element of#remember.