My current jQuery script is linked to a button and it functions by toggling font styles on a website by enabling or disabling a stylesheet upon clicking the button. Now, I want to enhance this functionality by saving user preference to a cookie so that their font choice persists across different parts of the site and sessions. Ideally, when a user clicks the button for the first time, the font changes as usual and the choice is saved in a cookie. Subsequent clicks should reflect this stored preference with an option to revert back to default font by erasing or changing the cookie value.
I have made numerous attempts to implement this feature but unfortunately, I haven't been successful in getting the cookie to save and maintain the font choice consistently. Any suggestions or assistance on how to achieve this will be highly appreciated.