jQuery(document).ready(function($) { $('.wpa-superstar-toggle input').on('change', function() { var $input = $(this); var option = $input.attr('name'); var value = $input.is(':checked') ? 1 : 0; // Remove any existing status messages $('.wpa-status').remove(); // Add a small notification that fades out var $notification = $('Setting saved'); $('body').append($notification); $.post(wpaSuperstar.ajaxurl, { action: 'wpa_superstar_update_option', option: option, value: value, nonce: wpaSuperstar.nonce }, function(response) { if (!response.success) { console.error('Error:', response); $notification.css('background', '#d63638').text('Error saving setting'); } // Fade out and remove the notification after 2 seconds setTimeout(function() { $notification.fadeOut(300, function() { $(this).remove(); }); }, 2000); }); }); });