Languages
[Edit]
EN

HTML - select radio input on click on related text

3 points
Created by:
Wiktor-Sribiew
830

In this article, we would like to show you how to select a radio input on click on the related text in HTML.

Quick solution:

 

OR:

 

Practical examples

Edit

1. Using input and label elements with id-for relation

Edit

In this example, we use input and label elements with id-for relation to enable radio input selection on the related text click (label text).

Note:

If the text inside the label element wasn't bound by an id - for relation, then the text could not be clicked.

 

2. Wrapping input with label element

Edit

In this example, we present how to enable radio input selection when you click the related text by wrapping the input and span elements with the label. This solution doesn't need the id and for attributes to specify the relation.

Note: by putting the text (e.g <span>Value 1</span>) outside the label element, you won't be able to click the related text anymore.

 

References

Edit
  1. <input type="radio"> - HTML | MDN
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join