Change click action of an element


I have a button on my scene, which has 2 timelines.

When users click on the button, they are taken to a time in the second timeline.

I’d like to keep the button at the same place, but, it should now change its click action to take users back to the first timeline when clicked on.

As of now, I’m doing this using z-index. I created a duplicate of the button and keep switching back and forth their z-indices just to make users believe that it’s the same button which is taking letting them switch timelines. This method is working, but, I was wondering if I could somehow just change the onclick action (and possibly the hover title) of the same button so that, I can eliminate the need for an extra DOM element.

I think the approach you have is good. The alternative is to keep track of a variable in JavaScript, which runs a different action on first click, and a different action on second click. You could swap classes (clickedonce) for example, using something similar like this: Stop action if trigger is clicked a second time

1 Like

That’s great, thanks! I’d try to implement the other solutions just as experiments.