Monitor element by class to see if it changes and grab new value -- JavaScript Only

894359
894359 used Ask the Experts™
on
How would I monitor and report if the value (dollar amount) in the  example below changes?  This is the only element with a class name of "amount" JavaScript only.

<div class="amount">$100.00</div>

Thanks!
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
NorieAnalyst Assistant

Commented:
How would the value be changed?

As far as I can see, since it's not in an input element, the user won't be able to change it.

Author

Commented:
Correct, it is not an input element, it is only an output. The the user changes it by changing a bunch of other things on the form. Isn't there a way to monitor this element and  detect when it changes?
Multitechnician
Top Expert 2014
Commented:
please note the script is at the end of the page to be sure the page is fully loaded
<script>
var bckamount = document.querySelector(".amount");
if(bckamount)
   bckamount = bckamount.value;
setInterval(function() {
   var amount = document.querySelector(".amount");
   if(amount && (bckamount != amount.value))
        alert("new value!");
}, 250);
</script>
</body>

Open in new window

NorieAnalyst Assistant

Commented:
894359

Why not monitor the other elements or the form itself?

When there's a change made there check if the value in the div has changed.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial