Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
javascript query selector issue

I am trying to select nested h2 tag by queryselector in javascript, but this seems like not working, I do not see any result on page.

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

HTML File

<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 Respostas
Responde à pergunta

0

You're using strange syntax.

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

should work better ;)

about 4 years ago · Juan Pablo Isaza Relatório

0

I'm not certain if you have a problem with the CSS selector in querySelector, but you may want to use querySelectorAll to select all element matching the selectors.

What doesn't look right is trying to set the background-color in your JavaScript code. Change the background-color setting in JavaScript with backgroundColor:

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

If you would like to use the querySelectorAll option, the following code would perform the same task for all elements matching your selector string:

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

Runnable example

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda