views:

52

answers:

2

Here is some code that checks if a radio button is disabled. How do I reform this to make the radio unchecked if it is currently disabled? And yes I still want to remove the parent CSS class. Thanks.

$('input:disabled', true).parent().removeClass("style1");

Why won't this work?

$('input:disabled', true).attr('checked', false).parent().removeClass("style1");
+1  A: 

How do I reform this to make the radio unchecked if it is currently disabled?

You could do:

$(':radio').each(function(){
  if ($(this).is(':disabled')) {
    $(this).attr('checked', false);
  }
});

More Info:

Sarfraz
I'm not using check boxes. I'm using radio buttons. I make a call to them using $('input') and they have a property named :checked.
nick
@Nick: I have updated my answer, please check.
Sarfraz
Thanks that works.
nick
@Nick: You are welcome...
Sarfraz
+1  A: 

You can use :radio to only get radio buttons. And with the additional :disabled you will only get disabled radio buttons. So try this:

$(":radio:disabled").removeAttr("checked").parent().removeClass("style1")
Gumbo
I'm trying to use radio buttons. This doesn't seem to work: $('input:disabled', true).attr('checked', false).parent().removeClass("style1");
nick
@Nick: Why do you use `true` as context? Please test the code as I wrote it.
Gumbo