Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
62
rated 0 times [  63] [ 1]  / answers: 1 / hits: 16838  / 12 Years ago, mon, july 30, 2012, 12:00:00

Possible Duplicate:

Listening for variable changes in JavaScript or jQuery






How can I track if this variable has changed?



var ConditionalFlag = 0;


I tried this:



var ConditionalFlag = 0;
$(ConditionalFlag).change(function () {
alert(Changed);
});
ConditionalFlag++;


But to no avail. I have considered using a 25ms timer to check for change like this:



var ConditionalFlag = 0;
function CheckFlag() {
if (ConditionalFlag > 0) {
alert(Changed);
clearInterval(check);
}
}
var check = window.setInterval(CheckFlag(), 25);
ConditionalFlag++;


However, that seems like overkill. Is there a way to attach an event handler to this variable with jQuery or javascript?


More From » jquery

 Answers
2

There's no event that gets triggered when a variable changes. JavaScript doesn't work that way.



When does this variable get changed? Just add a call to a function after it does.


[#83965] Monday, July 30, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
kennedysaraiw

Total Points: 552
Total Questions: 99
Total Answers: 109

Location: South Sudan
Member since Sun, Jul 11, 2021
3 Years ago
kennedysaraiw questions
Tue, Dec 14, 21, 00:00, 3 Years ago
Sun, Jul 11, 21, 00:00, 3 Years ago
Mon, May 17, 21, 00:00, 3 Years ago
Fri, Mar 12, 21, 00:00, 3 Years ago
;