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

169
Views
Estoy tratando de cambiar el fondo de una propiedad de "cuerpo" de CSS con JS ... Sigo recibiendo un error de consola de "newBgColor no está definido"

He estado tratando de usar una función para cambiar un color de fondo con DOM. Probablemente me estoy perdiendo algo súper "en mi cara" pero no puedo verlo

Mi código JS es -

 function changeBg() { let newBgColor = document.querySelector("body") console.log(newBgColor) newBgColor.style.backgroundColor = "white"; }
 The CSS Im hoping to change is - body { font-family: 'Open Sans'; font-weight: normal; max-width: 760px; background-color: #ffe8d6; margin: 0 auto; color: rgb(193, 178, 164); } `` I keep getting this error - ReferenceError - newBgColor is not defined.
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Aquí hay un ejemplo de lo que podría hacer, cargue el CSS en el <head> y cargue el JavaScript al final de la página.

 <!DOCTYPE html> <html> <head> <title>Body Bg Color</title> <style> body { font-family: 'Open Sans', sans-serif; font-weight: normal; max-width: 760px; background-color: #ffe8d6; margin: 0 auto; color: rgb(193, 178, 164); width: 100vw; height: 100vh; } </style> </head> <body> <script> function beigeBg() { let newBgColor = document.querySelector("body") console.log(newBgColor) newBgColor.style.backgroundColor = "beige"; } beigeBg(); </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!