# How to hide and show part of a notebook with a button?

I need to show the user a part of a notebook only if he clicks on a button (or on a checkbox). For example, the user can proceed only if he answers a question correctly in the notebook! Hope to be clear in the answer, thanks to all.

One possible solution is to use the CellTag option to keep track of the cell you want to display. Here is the code:

createHiddenCell[buttonText_, cellText_] := Module[
{cell, cellTag = ToString@Unique[], isHidden = True, modifyCell},
cell = TextCell[cellText, CellTags -> cellTag];
modifyCell[] := If[isHidden, CellPrint[cell],
NotebookLocate[cellTag]; NotebookDelete[]];
Button[buttonText,
modifyCell[]; isHidden = ! isHidden
]
]


Usage:

createHiddenCell["Do you like Mathematica?", "Thanks!"]


It will create a button with text "Do you like Mathematica?". And clicking it will toggle the display of your content in the second argument.

You can modify cell variable to create more complicated cell if you want.