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

137
Views
console.log de backgroundColor muestra "" en lugar del valor del color

Tengo un elemento de botón con id "btn". Quiero console.log la propiedad de color de fondo que se muestra en blanco en su lugar. ¿Cuál es el problema? Gracias.

 let btnColor = document.getElementById("btn").style.backgroundColor; console.log(btnColor)
 #btn{ display: block; margin: auto; width: 100px; height: 100px; border-radius: 3px; background-color: #74992e; }
 <button id="btn">Click on me</button>

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Utilizar este:

 let btnColor = window.getComputedStyle(document.getElementById(“btn”)).backgroundColor console.log(btnColor)

esta trabajando bien para mi

explique: a veces window.getComputedStyle obtendrá el objeto de estilo de un elemento, de modo que si llama a .backgroundColor , funcionará bien

resumen dos funciones :)

  • ventana.getComputedStyle(elemento).backgroundColor

  • elemento.estilo.fondoColor

about 4 years ago · Santiago Gelvez 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!