Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

323
Vistas
Changing text color after input is clicked

I created a change background color button using only css and the problem I'm facing is the text stays the same color after the background color changed.

The label's ID is "switch" for changing the background. The text's ID is "par".

Here is what I've tried:

document.getElementById("switch").onclick = function() {
  document.getElementById("par").style.color = 'red';
}

I put an alert message first to test it was working, and when I clicked on the input button the message box alert came up. Yet when I replace the alert box with the code from above, my text stays the same color.

Any recommendations?

about 4 years ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

document.getElementById("switch").addEventListener("click", ()=>{
 document.getElementById("par").style.color = 'red';
});
#switch{
height : 100px;
width : 100px;
background-color : orange;
opacity;0.25;
}
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  
    <div id="switch">
      <p id="par">foo bar </p>
    </div>
</body>
</html>

document.getElementById("switch").addEventListener("click", ()=>{
 document.getElementById("par").style.color = 'red';
});
about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda