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

127
Views
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
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!