How to select a radio when clicking on the text next to it?

Asked

Viewed 2,870 times

3

It’s very simple to make radio buttons. I’ve seen inputs of this kind around that allow you to click directly inside the circle or on top of the text that refers to each radio button.

How do you do that?

  • 2

    Search about label of HTML.

  • Oh... A lot simpler than I could imagine. Thank you.

1 answer

3


Just put the text inside an element <label> pointing to the ID of the input correspondent:

<input type="radio" name="cores" id="vermelho"><label for="vermelho">vermelho</label>
<input type="radio" name="cores" id="verde"><label for="verde">verde</label>
<input type="radio" name="cores" id="azul"><label for="azul">azul</label>
  • 2

    Or else <label><input etc /></label> that does not need to point to the ID ;)

  • 1

    Yeah, I don’t know why I never do that!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.