Toggle Visibility of Solutions in Bookdown

You have a bookdown book with exercises and solutions to those exercises. You would like to control visibility of the solutions. For example, when the bookdown file loads, you would like all the solutions to be hidden. You would like a button for each solution to toggle its visibility. How to do this? We faced this problem when preparing materials for our CVXR tutorial. A little Javascript can easily solve this problem.