Auto Collapse When Click On Other Tabs

Does anyone have the code for auto collapses when we click on other tabs?

I want the first image to collapses automatically, when I click on the second image.