To enable this switching mode, open Terminal and type these commands:
$ defaults write com.apple.dock single-app -bool TRUE
$ killall Dock
From now on, clicking on an application in the Dock will hide all other open apps while switching to the selected application. You will not see this behavior if you use Command-Tab to switch, or click directly on another application's windows. To disable the feature, repeat the above commands, but replace TRUE with FALSE. (Alternatively, you can delete the entry entirely with defaults delete com.apple.dock single-app.) Remember to restart the Dock as well.
For an easier method of implementing this feature, see this hint.

