I need help simplifying some code. I have a basic code that changes the colour of 3 buttons on click based on which button is active, the idea was to have the colours of the buttons change with the information in a multi-state box.
Thanks in advance.
$w . onReady ( function () {
$w ( “#button40” ). onClick (() => {
$w ( ‘#statebox8’ ). changeState ( “state1” );
} );
$w ( “#button41” ). onClick (() => {
$w ( ‘#statebox8’ ). changeState ( “state2” );
} );
$w ( “#button42” ). onClick (() => {
$w ( ‘#statebox8’ ). changeState ( “state3” );
} );
});
const greycolour = “#F0F0F0”
const whitecolour = “#FFFFFF”
$w . onReady (() => {
$w ( "#button41" ). onClick (() => {
$w ( "#button40" ). style . backgroundColor = whitecolour ;
} );
$w ( “#button40” ). onClick (() => {
$w ( "#button40" ). style . backgroundColor = greycolour ;
} );
$w ( “#button41” ). onClick (() => {
$w ( "#button41" ). style . backgroundColor = greycolour ;
} );
$w ( “#button40” ). onClick (() => {
$w ( "#button41" ). style . backgroundColor = whitecolour ;
} );
$w ( “#button42” ). onClick (() => {
$w ( "#button42" ). style . backgroundColor = greycolour ;
} );
$w ( “#button40” ). onClick (() => {
$w ( "#button42" ). style . backgroundColor = whitecolour ;
} );
$w ( “#button41” ). onClick (() => {
$w ( "#button42" ). style . backgroundColor = whitecolour ;
} );
$w ( “#button42” ). onClick (() => {
$w ( "#button41" ). style . backgroundColor = whitecolour ;
} );
});