Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

213
Views
How to hide a whole component on selecting a radio button

I am working on html file. I have two two labels(say L1 and L2). Each label has two radio buttons. I want to hide L2 and it's radio buttons if a user selects any radio button from L1.

I know this can be done using java script but how to capture the selection of radio buttons on which i can execute my java script.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I have prepared a version based on your question. Is this what you meant?

[HTML]

<div id="container" class="container">
    <div id="first-radio">
       <label for="L1">L1</label>
  <div class="radio-box">
    <input type="radio" name="L1" /> L1-first
  </div>
  <div style="margin-bottom: 15px" class="radio-box">
    <input type="radio" name="L1" /> L1-second
  </div> 
    </div>
  
    <div id="second-radio">
        <label for="L2">L2</label>
  <div class="radio-box">
    <input type="radio" name="L2" /> L2-first
  </div>
  <div class="radio-box">
    <input type="radio" name="L2" /> L2-second
  </div>
    </div>

[Javascript]

const container = document.getElementById("container");
const firstRadio = document.getElementById("first-radio");
const secondRadio = document.getElementById("second-radio");
const L1_Radio1 = container.children[0].children[1];
const L1_Radio2 = container.children[0].children[2];
const L2_Radio1 = container.children[1].children[1];
const L2_Radio2 = container.children[1].children[2];

const array1 = [L1_Radio1, L1_Radio2];
const array2 = [L2_Radio1, L2_Radio2];

function hideRadio() {
    array1.forEach(item => {
        item.addEventListener("change", () => {
            secondRadio.style.visibility = "hidden";
        });
    });

    array2.forEach(item => {
        item.addEventListener("change", () => {
            firstRadio.style.visibility = "hidden";
        });
    });
}

hideRadio();

You can watch it in action here: https://jsfiddle.net/s4onh9qk/6/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!