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

306
Views
¿Cómo uso document.getElementsByClassName().style para cambiar el color del texto?

Así que traté de hacer una función de modo de luz. Pero para hacer eso, necesito cambiar el color de algunos elementos, pero les he asignado clases. ¿Alguien me dice cómo usar la función document.getElementsByClassName() para cambiar el color de los elementos asignados a esa clase?

Intenté hacer esto (ver el segundo fragmento de código) pero solo afecta 1 elemento. Tengo 2 del mismo elemento con la misma clase en una página.

 <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width"> <title>title</title> <style> .myH1{ color:black; </head> <body> <script> function lightMode(){ document.body.style.background = "white"; document.getElementsByClassName("myH1").style.color="blue"; </script> <h1 class="myH1">Header</h1> <button onclick="lightMode()">☀</button> </body> </html>
 function lightMode() document.body.style.background="white"; const element = document.getElementsByClassName("myH1") element.style.color="black";
about 4 years ago · Juan Pablo Isaza
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!