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

209
Vistas
Why is my js returning an empty string when I check the background colour of an element?

I have an event listener which listens for a click on an element, and then runs a function that checks if the background colour of the element is white. Here is my code:

setting.addEventListener("click", (e) => {
       if (e.target.style.backgroundColor == "white") {
           e.target.style.backgroundColor = "black";
       } else {
           console.log(e.target.style.backgroundColor);
           e.target.style.backgroundColor = "white";
       }
});

My intention is that the element will first turn black, since its background colour is white.

Here is my css for this element:

.toggle {
    display: inline-block;
    height: 20px;
    width: 20px;
    background-color: white;
    border-radius: 50%;
    position: absolute;
    right: 300px;
    outline: 3px solid black;
    border: 3px solid white;
}

The console log in the js logs this message:

<empty string>

Why is this happening, and how should I fix it?

about 4 years ago · Juan Pablo Isaza
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