(function($){ $( document ).ready( function() { var _setPreviewButton = function( iButtonID, oThis ) { oThis.closest( 'fieldset' ) .find( '.amazon-auto-links-button' ) .each( function(){ // console.log( $( this ).attr( 'class' ) ); $( this ).attr( 'class', // the suject attribute name 'amazon-auto-links-button amazon-auto-links-button-' + iButtonID // value ); if( undefined !== aal_button_preview_labels[ iButtonID ] ) { $( this ).text( aal_button_preview_labels[ iButtonID ] ); } // Make sure the button container is visible. By default it is hidden for widget forms. $( this ).parent().show(); } ); } // Initially set the preview. $( '.button-select-row' ) .find( 'select' ) // the select tag .each( function() { // hook the change _setPreviewButton( $( this ).val(), // button id $( this ) // caller element ); } ); // Hook the button select change. $( '.button-select-row' ) .find( 'select' ) // the select tag .change( function() { // hook the change _setPreviewButton( $( this ).val(), // button id $( this ) // caller element ); } ); } ); // document ready }( jQuery ));