How to select radio button by clicking its div?

Felipe

I have created 5 categories of radio buttons, each with 3 choices to choose from. I have inserted these radio buttons into its respective divs. While building the radios buttons, I had believed that when the user clicks on the div itself, the radio button will be selected as well. I found out that this is not the case. At first I set input [type=radio] opacity 0 so the circle box is hidden, dont want it to show. I removed this css property to see if its being selected but its not. Is there a way to select the radio button without clicking on the circle, and by clicking on the div that it is in? Im think that maybe my HTMl is incorrect, not sure where to go with this. Any tips are greatly appreciated. I will post html of one category of the radio buttons and current display of the radio buttons.

<main class="subscription__container">
      <section
        id="preferences"
        class="subscription__container--preferences box"
      >
        <div class="question__container">
          <h3 class="question__container--title">
            How do you drink your coffee?
          </h3>
          <img
            class="question__container--img"
            src="../assets/plan/desktop/icon-arrow.svg"
            alt="arrow"
          />
        </div>
        <div class="options__container">
          <div class="options__container--option">
            <input
              id="capsule"
              type="radio"
              data-preference="Capsule"
              value="Capsule"
              name="preferences"
              checked
            />
            <label for="capsule"></label>
            <h4 class="options__container--title">Capsule</h4>
            <p class="options__container--description">
              Compatible with Nespresso systems and similar brewers.
            </p>
          </div>
          <div class="options__container--option">
            <input
              id="filter"
              type="radio"
              data-preference="Filter"
              value="Filter"
              name="preferences"
            />
            <label for="filter"></label>
            <h4 class="options__container--title">Filter</h4>
            <p class="options__container--description">
              For pour over or drip methods like Aeropress, Chemex, and V60.
            </p>
          </div>
          <div class="options__container--option">
            <input
              id="espresso"
              type="radio"
              data-preference="Espresso"
              value="Espresso"
              name="preferences"
            />
            <label for="espresso"></label>
            <h4 class="options__container--title">Espresso</h4>
            <p class="options__container--description">
              Dense and finely ground beans for an intense, flavorful
              experience.
            </p>
          </div>
        </div>
      </section>
</main>

current look, is there a way to select radio button by clicking on its div and radio circle to display none?

Spectric

Your labels are not surrounding the div contents. They are currently just empty labels (e.g, <label for="capsule"></label>), so obviously nothing is happening.

This should work:

<main class="subscription__container">
      <section
        id="preferences"
        class="subscription__container--preferences box"
      >
        <div class="question__container">
          <h3 class="question__container--title">
            How do you drink your coffee?
          </h3>
          <img
            class="question__container--img"
            src="../assets/plan/desktop/icon-arrow.svg"
            alt="arrow"
          />
        </div>
        <div class="options__container">
          <div class="options__container--option">
            <input
              id="capsule"
              type="radio"
              data-preference="Capsule"
              value="Capsule"
              name="preferences"
              checked
            />
            <label for="capsule">
            <h4 class="options__container--title">Capsule</h4>
            <p class="options__container--description">
              Compatible with Nespresso systems and similar brewers.
            </p></label>
          </div>
          <div class="options__container--option">
            <input
              id="filter"
              type="radio"
              data-preference="Filter"
              value="Filter"
              name="preferences"
            />
            <label for="filter">
            <h4 class="options__container--title">Filter</h4>
            <p class="options__container--description">
              For pour over or drip methods like Aeropress, Chemex, and V60.
            </p></label>
          </div>
          <div class="options__container--option">
            <input
              id="espresso"
              type="radio"
              data-preference="Espresso"
              value="Espresso"
              name="preferences"
            />
            <label for="espresso">
            <h4 class="options__container--title">Espresso</h4>
            <p class="options__container--description">
              Dense and finely ground beans for an intense, flavorful
              experience.
            </p></label>
          </div>
        </div>
      </section>
</main>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to make a radio button unchecked by clicking it?

Toggle HTML radio button by clicking its label

How to transition div on button clicking

How to select a radio button by default?

How can I toggle disable on a select and its parent div and its neighbor button

VueJS - how to show different div on radio button select

How to click radio by clicking on div?

Python How to Select a Radio button

how to check a radio button by clicking on a table row?

How to activate a cell on clicking a radio button in Excel?

Clicking on a disabled radio button

How to uncheck radio button upon double clicking?

trigger radio by clicking on div

How to output the price when clicking the radio button?

Clicking radio button doesn't show other div

Clicking button to add its text to another div

Select radio button on clicking parent div and get its value in angularJS

On clicking first radio button, automatically open radio button inside of that div

how to use dojo to show/hide DIV by clicking radio button?

How to get value in a td by clicking its button

Div not show/hide on radio button select

How to submit the value of Radio Button by clicking on the Answer/DIV

Clicking on radio button

Enable <select> <option> after clicking radio button

Robotframework - How can I select this type of radio button by means of the text in its associated label?

How to Randomly select the dynamic value by clicking on the Radio button in a table -Not able to click on the Radio button

React: How can I remove a specific div element after clicking its associated button?

How to select the first option in a radio button group with selenium when its ID changes with every new page load

problem in clicking radio button can't able to select a radio button