Blabla Blabla - 4 months ago 10
jQuery Question

Get result of function used in .on

I have function, lets name it

X1
, which returns variable Y. This function is used in action
.on("focusout", X1)
. How I can get variable
Y
? The result of
X1
when after executing
.on
?

Answer

You could change the scope of Y to sit outside the scope of the function X1

var Y = 0;
var X1 = function () { Y++; };

myelement.on("focusout",X1);

function doCheck() {
   if (Y == 1) {
     //etc...
   }
}