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

129
Visualizações
JavaScript run if else statement again after value change

new to JavaScript so please bear with me! I'm stuck in a research rut and not sure on the best way forward with this one

I'm attempting to put together the statement below, but not sure about how to best have the script run again/re-check the if else statement once the TotalPrice value updates.

The TotalPrice dynamic value is within <span class="money"></span> and increases/decreases based on user input (quantityDown & quantityUp +/- DIVs)

var TotalPrice = 0;

if (TotalPrice == 0) {
  document.write('<div>PRICE IS 0</div>');
} else {
  document.write('<div>PRICE IS NOT 0</div>');
}
<div id="quantityDown_0_0" class="quantity-down" mindx="0_0" vindex="0" onclick="quantityDown(this)"></div>

<div id="quantityUp_0_0" class="quantity-up" mindx="0_0" vindex="0" onclick="quantityUp(this)"></div>

<span class="money">£0</span>

The basic code above is working correctly on the initial page load (producing <div>PRICE IS 0</div>), but once the <span class="money">£0</span> value changes, the else statement is not running

Where I'm at so far...

  • Am I right in thinking/on the correct path that I need to setup an event listener that checks for any changes on the <span class="money"></span>? That'll re-run the JavaScript when/if its value changes?

I appreciate this is fairly basic JavaScript, so any advice on how to apply this for a learner would be massively appreciated!

about 4 years ago · Santiago Gelvez
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