Toggling search custom button

Hi! Some time ago I asked whether I can insert search in custom place, and received an answer Header search in custom header - #2 by awesomerobot. But there is a question from this: can I toggle visibility of the search by clicking on custom button, or it can be done with jquery only? What is the correct way to do this?