The Muffin Man
The Muffin Man

Reputation: 20004

How can I uncheck disabled radio buttons using jQuery?

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");

Upvotes: 2

Views: 3036

Answers (2)

Sarfraz
Sarfraz

Reputation: 382696

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:

Upvotes: 2

Gumbo
Gumbo

Reputation: 655229

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")

Upvotes: 1

Related Questions