So first of all I’d like to clarify that I’m a novice at coding- I’m a designer, not a coder.
I wrote some code to change the state of a Multi-State Box when certain text is clicked on, and since that text is duplicated across all the states, I put those elements into an array so I didn’t have to call the onClick function for them individually.
The site is not live yet, so I’m only checking it through the Site Preview option and it’s throwing up a bunch of errors that my small, non-coder brain cannot comprehend. There are no errors in Preview mode from the editor.
This is the code, please forgive its messiness:
$w.onReady(function () {
switchOnClick();
});
const econ = $w("#econTextP, #econTextC, #econTextT, #econtextL, #econTextD");
const politics = $w("#politicsTextE, #politicsTextC, #politicsTextT, #politicsTextL, #politicsTextD");
const climate = $w("#climateTextE, #climateTextP, #climateTextT, #climateTextL, #climateTextD");
const tech = $w("#techTextE, #techTextP, #techTextC, #techTextL, #techTextD");
const life = $w("#lifeTextE, #lifeTextP, #lifeTextC, #lifeTextT, #lifeTextD");
const edu = $w("#eduTextE, #eduTextP, #eduTextC, #eduTextT, #eduTextL");
function switchToRelevant(state) {
$w('#multiStateBoxArticles').changeState(state);
}
function switchOnClick() {
econ.onClick(() => {
switchToRelevant('econState')
})
politics.onClick(() => {
switchToRelevant('politicsState')
})
climate.onClick(() => {
switchToRelevant('climateState')
})
tech.onClick(() => {
switchToRelevant('techState')
})
life.onClick(() => {
switchToRelevant('lifeState')
})
edu.onClick(() => {
switchToRelevant('eduState')
})
}