ThinkingStiff has a pretty good idea.
You could also add and remove a class to for your search box, and only use the after tag with that.
Something like .hide:after { display:none } and .show:after { /* normal css */ }. Then just swap these classes with javascript.
edit: mixed up the names