WP Customizer compare and set a value via javascript

I’m working on a theme which allows users to choose from a set of color palettes and I need to add more color controls so the user can change the background colors of sections of the site, which are controled based on the color palette. Until the user sets a custom color, I need the colors on these options to be updated (without refreshing) based on the color palette that is selected.

I need something simillar to Weston Ruter’s answer on this question but I can’t seem to figure out how to compare the current value and set the color according to it.

The following code updates the color without refreshing, but only to the option on the last “else” statement, whenever I try to compare the values it doesn’t work.

wp.customize( ‘themeb_scheme’, ‘themeb_footerbg’, function( themeb_scheme, themeb_footerbg ) {
themeb_scheme.bind( function( value ) {

if( themeb_scheme == ‘light’){
themeb_footerbg.set( ‘#eaeaea’ );
} else if( themeb_scheme == ‘dark’){
themeb_footerbg.set( ‘#323232’ );
} else {
themeb_footerbg.set( ‘#828282’ );
}

} );

} );

I have zero experience with jquery, the person that coded the layout is no longer working with us and I was asked to make those changes, so any help would be highly appreciated.

Read more here:: WP Customizer compare and set a value via javascript

Leave a Reply

Your email address will not be published. Required fields are marked *