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

115
Visualizações
Observe change and logging it outJS

On our website when you click on one of the size's it would display a different price per size which works fine. For example size a = $10, size b = $20, size c = $30. What I'm trying to do however is when the price changes I want to take that value and use it to run another calculation.

The issue I have is that when I try and observe the change the value always stays the same i.e the price for size a ($10) gets printed each time. Not sure if anyone can help - below is a mockup example of how the code looks similar to onsite.

const elementToObserve = document.querySelector(".container");
const price = document.querySelector('.price');
const observer = new MutationObserver(function() {
  console.log(price.innerHTML);
});

observer.observe(elementToObserve, {
  subtree: true,
  childList: true
});
<div class='container'>
<ul class='buttons'>
  <li>size a</li>
  <li>size b</li>
  <li>size c</li>
</ul>

<p class='price'></p>
</div>

about 4 years ago · Juan Pablo Isaza
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