-2

I am trying to remove checked group radio list. How to do that?

    <div class="row padding-4">
          <div class="col-md-10 col-md-offset-1">
              <input id="SecondaryDiscipline" name="SecondaryDiscipline" type="radio" value="Test1">
              Test1
          </div>
     </div>
   <div class="row padding-4">
          <div class="col-md-10 col-md-offset-1">
              <input id="SecondaryDiscipline" name="SecondaryDiscipline" type="radio" value="Test2">
              Test2
          </div>
     </div>
   <div class="row padding-4">
          <div class="col-md-10 col-md-offset-1">
              <input id="SecondaryDiscipline" name="SecondaryDiscipline" type="radio" value="Test3">
              Test3
          </div>
     </div>

I tried below both. I select first one below code is working. other than that it is not working

method 1#

 $("#SecondaryDiscipline").each(function (i, x) {
                        if ($(x).is(":checked")) {
                            $(x).removeAttr("checked");
                        }
                    });

method 2

$('#SecondaryDiscipline').removeAttr('checked');
James123
  • 11,184
  • 66
  • 189
  • 343

2 Answers2

1
  • Your id #SecondaryDiscipline is repeating. Its not correct.

  • You can make that a class. ie <input class="SecondaryDiscipline" name="SecondaryDiscipline" type="radio" value="Test1">

Then both the method will work fine

  • Another method is selecting by name. $('input[name=SecondaryDiscipline]')
Rino Raj
  • 6,264
  • 2
  • 27
  • 42
1

Do this:

$('[name="SecondaryDiscipline"]').removeAttr('checked');

Also, note that you should not have multiple elements with the same ID.

Rick Hitchcock
  • 35,202
  • 5
  • 48
  • 79