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

What is Framer? Join the Community
Return to index
Michael Middleditch
Posted Jan 21 - Read on Facebook

I have a for loop creating a row of buttons & setting up 2 states. I want to change the state of the clicked button to stateA & the others to stateB
- Do I need an 'if' statement or a click handler or is there a simple line i can add to the following?

for btn in btnBandSizeTxt
btn.on Events.Click, (event,btn) ->
btn.states.switch("stateA")
bandSize = event.target.innerHTML
updateFilters()

Thanks all :)

2 Comments

Benjamin Den Boer

Heya Michael Middleditch, yeah, you can easily use a single conditional statement to target the currently clicked button. Let's say you have an array of 3 buttons. The indeces of arrays start at 0, so the first button would be btnBandSizeTxt[0]. To single out the first button, yet switch all others:

for btn in btnBandSizeTxt
____btn.states.switch("stateB")

if this is btnBandSizeTxt[0]
____this.states.switch("stateA")

This should do the trick. :-)

Michael Middleditch

That's amazing - perfect, thanks a mil!

Read the entire post on Facebook