Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

128
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda