I'm making a Doughnut Flavor Selector. I've made a few buttons to change the color of the Oval lying behind the doughnut. But I want to be able to change the text in "Pick a flavor" to the name/Id of the Button clicked on.
// Change the text in an element
This works fine... But it shows the Root swell (Stage_Strawberry)... And I want it to only show Strawberry. Is there a way to do this easily?
I would like to bypass putting things in variables. I want to make it as easy as possible...
It would be cool to copy and paste a button, change the name of the symbol... and done...
1) Because the "Stage_" length is 6 (6 characters), therefore e.currentTarget.id.slice(6) returns "Strawberry".
2) You can also replace "Stage_" by nothing. So, e.currentTarget.id.replace("Stage_", "") returns "Strawberry".
What a great solution! Thank you! Problem solved. And it's an easy line of code to understand.
Thank you! You seriously made my day!