This is a read-only archive of the Framer Community on Facebook.

What is Framer? Join the Community
Return to index
Chris Camargo
Posted May 27 - Read on Facebook

I'm really scratching my head here... Why am I getting the correct value for i placed in the html here, but every time I click to retrieve my layer's name, I get the last number iterated?

6 Comments

Chris Camargo

Chris Camargo

Actually, this doesn't seem to have anything to do with the iterator value. If I insert my own data, clicking each box always returns the value of the last layer pushed to the array. http://share.framerjs.com/vl2uepxb3ud9/

Koen Bok

Yes, this is a confusing part about javascript: http://stackoverflow.com/questions/111102/how-do-javascript-closures-work

To get around this, use the layer argument from the callback:
http://share.framerjs.com/j5i3dtjfyv5w/

Koen Bok

In the simplest language, the layer value in your click handler references to whatever layer is at the click moment, not when you set the handler up.

Chris Camargo

Ah, so simple! Thanks, Koen.

Antonio Krämer Fernandez

layer name is a different property that you have to set. Maybe this also helps you:
http://share.framerjs.com/h4lu7bdu3gvq/

Read the entire post on Facebook