Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

73
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda