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

71
Views
by changing the selection of radio button now working fine

if first time I want to select or changing the radio button I want to change the label color to red, but it not working perfectly, I use a on change function inside radio button

<script>
    function changecolor(){
      document.getElementsByClassName("label").style.color='red'
    }
  </script>
<body>
<div class="group">
  <label for="one" class="label">Select Any</label>
    <div class="input">
     <input id="one" class="radio" name="radio-group" type="radio" onchange="changecolor()" >
      <input id="one" class="radio" name="radio-group" type="radio" onchange="changecolor()">
   </div>
</div>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

document.getElementsByClassName return an htmlcollection so you have two solutions to make work your code

  • iterate on each element of the htmlcollection and apply the style
  • or use an index for access one of the specific element

function changecolor(){
  document.getElementsByClassName("label")[0].style.color='red'
}
<div class="group">
  <label for="one" class="label">Select Any</label>
    <div class="input">
     <input id="one" class="radio" name="radio-group" type="radio" onchange="changecolor()" >
      <input id="one" class="radio" name="radio-group" type="radio" onchange="changecolor()">
   </div>
</div>

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!