1

Is it possible to cancel the checked HTML property for a radio button using JavaScript?

I have this layout:

<div class="wss_final_delivery">
  <div class="wss_final_delivery_wrap">Would you like to accept final delivery
    <label>
      <input type="radio" name="wss_accept_delivery" value="yes">
        Yes
    </label>
    <label>
      <input type="radio" name="wss_accept_delivery" value="no" checked="">
        No
    </label>
  </div>
</div>

This results in the "No" option to be checked by default. I would like none of the options to be checked by default and let the user choose his option. However, I can not change the HTML code. Is it possible to achieve using JavaSricpt?

3
  • document.querySelectorAll("[name='wss_accept_delivery']").forEach(function(item){item.checked = false;}); Commented Dec 5, 2021 at 16:14
  • 2
    This should provide additional information. Commented Dec 5, 2021 at 16:16
  • 1
    Does this answer your question? How to clear radio button in Javascript? Commented Dec 5, 2021 at 16:17

1 Answer 1

1

You can do it using javascript, like this:

 document.querySelectorAll("[name='wss_accept_delivery']").forEach(radio=> {
  radio.checked = false;
  radio.removeAttribute('checked')
 });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.