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

102
Vistas
The element sent to my event listener have no css properties?

Let's say I need a button that can change style when mousedown event happen, and recover to it's normal style when mouseup event fired.

What I'm trying to do is to cache the old css styles in the mousedown event handler, so they can be available for mouseup event handler (They are way too many, I don't want to set them one by one).

But as the following code shows, when browser callback my event listener, it pass to me a button object without any css style properties.

My question is: did I miss something? Or it's just suppose to be so? If this is the case, how can I get it's css style properties when javascript select a DOM element?

let show = function(key) {
  console.log(key.style.backgroundColor); // should be red
};

const btn = document.querySelector('.button');
btn.addEventListener('click', () => {
  show(btn);
});
.button {
  width: 100px;
  height: 40px;
  background-color: red;
}
<button class="button">Click me to show "red"</button>

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