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

193
Views
Encuentre la clase css en div y obtenga valores

Estoy tratando de encontrar una clase en un div (donde el valor siempre terminará en 0bg ), dada una cadena parcial y luego obtengo su valor de estilo de fondo.

Por ejemplo:

 .xx-color-100bg{ background-color: #323334; }
 <div class="heading xx-color-100bg"></div>
 document.querySelectorAll(".heading").classList.contains("0bg").style.background

La solución de los errores anteriores con Cannot read properties of undefined (reading 'contains')

¿Cómo puedo encontrar la clase necesaria y obtener su valor de color de fondo?

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

querySelectorAll() devuelve una NodeList , por lo que no puede usar classList . Debe recorrer los DOMElements en la lista o simplemente asumir que el primero es lo que necesita:

 document.querySelectorAll(".heading").forEach(e => { // do something with e.classList }); // OR document.querySelectorAll(".heading")[0].classList // the first element
about 4 years ago · Santiago Gelvez Report

0

Descubrí la solución justo después de publicar la pregunta:

 window.getComputedStyle(document.querySelector(".heading[class*='0bg'")).backgroundColor;
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!