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

373
Views
cambiar el color usando JavaScript (DOM)
 const box = document.getElementsByClassName('box'); let colorAsString = '#FEC6F0'; let colorAsNumber = #FEC6F0; Array.from(box).forEach((element) =>{ element.style.backgroundColor = colorAsString; element.style.backgroundColor = colorAsNumber; });

Guardé un valor de color hexadecimal en una cadena, así como un número y pasé la variable como un valor para la propiedad css. ¿Por qué este código no funciona me puede explicar ...!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Cuando edita la propiedad de estilo, al final es solo una cadena CSS. Así que para representar colores puedes usar formatos como: '#ffffff' o 'rgb(255,255,255)'. Pero no puedes usar un número.

Puede leer más sobre eso aquí: https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style

 const box = document.getElementsByClassName('box'); let colorAsString = '#FEC6F0'; Array.from(box).forEach((element) =>{ element.style.backgroundColor = colorAsString; });
 .box { width:100px; height:100px; margin:10px; background-color:gray; }
 <div class="box"></div> <div class="box"></div> <div class="box"></div>

about 4 years ago · Juan Pablo Isaza Report

0

Esta funcionando

 <html> <body> <p id="p"> on click change my color </p> <script> onclick = function(){ document.getElementById("p").style.color = "#fff"; document.getElementById("p").style.background = "#000"; } </script> </body> </html>
about 4 years ago · Juan Pablo Isaza 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!