Categories
HTML

How to Toggle an HTML Radio Button by Clicking its Label?

Spread the love

Sometimes, we want to toggle an HTML radio button by clicking its label.

In this article, we’ll look at how to toggle an HTML radio button by clicking its label.

Toggle an HTML Radio Button by Clicking its Label with JavaScript

To toggle an HTML radio button by clicking its label with JavaScript, we should put the radio button and the radio button text in the label element.

For instance, we can write:

<label>  
  <input type="radio" name="mode" value="create">  
  <i>create table</i>  
</label>

We put the input and i element with the label text so that when we click on the text, the radio button will be selected.

Conclusion

To toggle an HTML radio button by clicking its label with JavaScript, we should put the radio button and the radio button text in the label element.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *