Anand Deva

Anand Deva

  • NA
  • 43
  • 4k

HTML Radio button - Aria-Checked to be changed using javascript/jquery

Jul 14 2021 11:08 AM

Jquery :

 

    <script type="text/javascript">
        $(document).ready(function () {
            $(document).on('click', 'input[name="Radios"]', function () {
                alert($(this).val());
                if (($(this).val()) == "Yes") {
                    document.getElementById("spanyes").setAttribute(aria-checked, true);
                    document.getElementById("spanno").setAttribute(aria-checked, false);
                }
                if (($(this).val()) == "No") {
                    document.getElementById("spanyes").setAttribute(aria-checked, false);
                    document.getElementById("spanno").setAttribute(aria-checked, true);
                }
            });
        });
    </script>

 

 

.aspx file :

 

          <div id="Radio">
                            <div class="radio" role="radio">
                                <label>
                                    <input type="radio" id="yes" name="Radios" value="Yes" required=""/>
                                    <span id= "spanyes" for="yes" class="custom-control-radio" aria-checked="false" aria-label="" tabindex="0"></span>
                                    <span class="radio-text">Yes</span>
                                </label>
                            </div>
                            <div class="radio" role="radio">
                                <label>
                                    <input type="radio" id="no" name="Radios" value="No" required=""/>
                                    <span  id= "spanno" for="no" class="custom-control-radio" aria-checked="false" aria-label="" tabindex="0"></span>
                                    <span class="radio-text">No</span>
                                </label>
                            </div>
                        
        </div>


Answers (1)