Samar Rizvi
Samar Rizvi

Reputation: 433

Radio button is checked although checked attribute is removed

I am using the following code:

$('#send_order_form input[type="radio":checked]').each(function(){ this.checked = false; });

But I still see the radio button clicked. On inspecting element, checked attribute is actually removed. Wierd, I am using chrome.

Upvotes: 0

Views: 131

Answers (4)

Samar Rizvi
Samar Rizvi

Reputation: 433

I was using form within a form. That's why the problem was occurring. Now after removing the child form, the problem is solved.

Upvotes: 0

antony
antony

Reputation: 2893

You have a slight error in your selector for checked inputs. Try this:

$('#send_order_form input[type="radio"]:checked').each(function(){ 
      this.checked = false;
});

Or even better

$('#send_order_form input[type="radio"]:checked').attr('checked', false);

Upvotes: 0

Katie Kilian
Katie Kilian

Reputation: 6993

Try this:

$('#send_order_form input[type="radio":checked]').each(function(){ 
    $(this).prop('checked',  false); 
});

Upvotes: 0

Wilson Freitas
Wilson Freitas

Reputation: 583

Try to remove the checked attribute using jquery removeAttr instead:

$('#send_order_form input[type="radio":checked]').each(function(){ $(this).removeAttr("checked"); });

Upvotes: 1

Related Questions