JQuery checkbox fail (why won't it changed "checked" attr?) -
i want toggle disabled/enabled form based on users click of edit checkbox. simple stuff.
while disabling component works, checkbox's default checked behavior overriden. tried return attr("checked",true) work no dice. i'm assuming might have markup (placing checkbox in div). can't figure out.
$(function(){ $('#target :input').attr('disabled','disabled'); $(':checkbox').toggle( function(){ $(this).attr("checked",true); $('#target :input').attr('disabled',false); }, function(){ $('#target:input').attr('disabled','disabled'); $(this).attr("checked", false); }); });
thanks, brendan
as @devbook.co.uk noted, toggle-event
[docs] method breaks default behavior of checkbox.
one solution use .change()
event, along this.checked
property of checkbox.
example: http://jsfiddle.net/efpr6/
$('#target :input').attr('disabled', 'disabled'); $('#toggler').change(function() { $('#target :input').attr('disabled', !this.checked); });
Comments
Post a Comment