Say I have a function like this:
var some_value = 0
function refresh(something)
{
// Log our value
console.log(some_value);
// If this function was invoked by clicking our some_div created below, set some_value
if(last.getAttribute("baby"))
{
some_value = 1;
}
// Create some div, give it a random attribute and add an onclick event
some_div.setAttribute("baby");
some_div.addEventListener("click", function(){refresh(this);}, false);
// Log our some_value
console.log(some_value);
}
// Call our function
refresh(null)
I would expect the console to look like this:
//refresh(null)
0
0
//clicked our some_div
0
1
Instead if looks like this:
//refresh(null)
0
0
//clicked our some_div
1
1
When is my some_value being set? This is making me crazy. I would really appreciate some help...