javascript - Are jQuery selectors snapshots or are they updated in real time -


i have variable y derived jquery selector:

function g() {     jquery('.myproperty').each(function(){         var x = jquery(this);         f(x);     }); }  function f(x) {     var y = x.siblings('someproperty').children('someclass');     var myvalue = random();     y.myvalue = myvalue;     jquery.ajax(         /* ... */         success: function {             if (myvalue != y.myvalue) {                 /// something!             } else {                 /// else!             }         }     ); } 

now, let's suppose g() event handler runs whenever user clicks button. means can fire in succession. since f() fires asynchronous ajax call, browser not block until succeeds , may arrive in random sequence after f() calls done (remember, don't block on ajax calls , complete), instance:

the issue facing y in each ajax call appears snapshots of actual dom object because state of y.myvalue not appear change despite perturbations calls g() (and f() extension) occurred before call function run.

i wonder if there ways refresh jquery selectors state of y can updated.

edit: clarify concern, example event queue:

g() /// sets y.myvalue 1.5555 g() /// sets y.myvalue 634.34 g() /// sets y.myvalue 555555 ajax call // reads y.myvalue 1.5555 when should 555555 ajax call // reads y.myvalue 555555 correct g() /// sets y.myvalue 4232 ajax call // reads y.myvalue 4232 correct ajax call // reads y.myvalue 634.34 when should 634.34 

this can hypothetically occur when there there fluctuations response times in server.

jquery objects not snapshots of dom. wrappers, objects containing references dom elements (that match selector). fact every time use jquery function, create new instance of jquery object. g() functions passes new instance f() everytime. f creates myvalue property on newly created jquery object instance. create new success handler every ajax call. y.myvalue , myvalue equal because create new instances of everytime , tell values equal.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -