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

135
Views
Problema con el selector de consultas de javascript

Estoy tratando de seleccionar la etiqueta h2 anidada mediante queryselector en javascript, pero parece que esto no funciona, no veo ningún resultado en la página.

 var changeTextForBundle = document.querySelector('.picky-bundler-container .picky-custom-html h2'); changeTextForBundle.style.background-color:='#363636';

Archivo HTML

 <div data-v-3efab0bc="" class="picky-bundler-container picky-widget"> <div data-v-3c43f93f="" data-v-3efab0bc="" class="picky-custom-html"> <h2 style="width:100%; display:flex; justify-content:center; align-items:center;">Frequently Bought Together</h2> </div> </div>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Estás usando una sintaxis extraña.

 var changeTextForBundle = document.querySelector('.picky-bundler-container .picky-custom-html h2'); changeTextForBundle.style.backgroundColor='#363636';

debería funcionar mejor ;)

about 4 years ago · Juan Pablo Isaza Report

0

No estoy seguro si tiene un problema con el selector de CSS en querySelector , pero es posible que desee usar querySelectorAll para seleccionar todos los elementos que coincidan con los selectores.

Lo que no se ve bien es intentar establecer el background-color en su código JavaScript. Cambie la configuración background-color en JavaScript con backgroundColor :

 var changeTextForBundle = document.querySelector('.picky-bundler-container .picky-custom-html h2'); changeTextForBundle.style.backgroundColor = '#363636';

Si desea utilizar la opción querySelectorAll , el siguiente código realizará la misma tarea para todos los elementos que coincidan con su cadena de selección:

 var changeTextForBundle = document.querySelectorAll( ".picky-bundler-container .picky-custom-html h2" ); changeTextForBundle.forEach(function (element) { element.style.backgroundColor = "#363636"; });

ejemplo ejecutable

 var changeTextForBundle = document.querySelectorAll( ".picky-bundler-container .picky-custom-html h2" ); changeTextForBundle.forEach(function(element) { element.style.backgroundColor = "#363636"; });
 <div class="picky-bundler-container picky-widget"> <div class="picky-custom-html"> <h2 style="width:100%; display:flex; justify-content:center; align-items:center;">Frequently Bought Together</h2> </div> </div>

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!