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

273
Views
No se puede establecer el atributo de document.documentElement;

Tengo el siguiente código para configurar el modo oscuro para el document.body

 function myFunction() { var element = document.body; element.classList.toggle("dark-mode"); }
 .dark-mode { background-color: black; color: white; }
 <label class="switch"> <input onclick="myFunction()" type="checkbox"> <span class="slider round"></span> </label>

Si configuro document.body en document.documentElement , no funciona. ¿Alguien sabe cómo solucionarlo para el elemento raíz del HTML? También probé document.querySelector(":root"); .

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

0

Entonces, el código tal como lo tiene parece estar funcionando bien, tanto document.body como document.documentElement , por lo que el problema podría estar relacionado con dónde y cómo está importando el CSS.

Con document.documentElement

 <style> .dark-mode { background-color: black; color: white; } </style> <label for="toggle" class="switch"> Toggle <input onclick="myFunction()" type="checkbox"> <span class="slider round"></span> </label> <script> function myFunction() { var element = document.documentElement; element.classList.toggle("dark-mode"); } </script>

Con document.body

 <style> .dark-mode { background-color: black; color: white; } </style> <label class="switch"> Toggle <input onclick="myFunction()" type="checkbox"> <span class="slider round"></span> </label> <script> function myFunction() { var element = document.body; element.classList.toggle("dark-mode"); } </script>

Pero también como recomendación general, la entrada no debe estar envuelta en la etiqueta.

 <style> .dark-mode { background-color: black; color: white; } </style> <label for="toggle" class="switch"> Toggle </label> <input id="toggle" name="toggle" onclick="myFunction()" type="checkbox"> <span class="slider round"></span> <script> function myFunction() { var element = document.body; element.classList.toggle("dark-mode"); } </script>

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!