+ 5
How to assign the value of a closure variable to a global variable.
var x=""; // here is the closure (function (index){ //click handler on array of elements to retrieve //their index ... [i].onclick=function (){ /*What happens here? can we assign the index variable here to a global one like x and later do stuff with x */ return x } })(i);
2 odpowiedzi
+ 4
basically I have 4 images on a main page. I want onclick to open the target link and retrieve the clicked image src and append it to a div on the target page.
+ 1
I'm not sure to understand what you want to achieve, but you could probably attach it to the window like "window.x = value" to be sure to retrieve it later.