Researchers found that, in general, people use social media to connect with people who are posting positive and success-oriented updates.
"But when people are in a negative mood, they start to show more interest in the less attractive, less successful people on their social media sites," said Silvia Knobloch-Westerwick, co-author of the study and professor of communication at The Ohio State University.
These findings give more context to recent studies that found people who spend a lot of time on Facebook tend to be more frustrated, angry and lonely presumably because of all the happy updates from friends that make them feel inadequate.
"People have the ability to manage how they use social media," said co-author of the study Benjamin Johnson, an assistant professor at VU University Amsterdam.
"Generally, most of us look for the positive on social media sites. But if you're feeling vulnerable, you'll look for people on Facebook who are having a bad day or who aren't as good at presenting themselves positively, just to make yourself feel better," said Johnson.
The study involved 168 college students. Researchers first put participants in a good or bad mood by having them take a test on facial emotion recognition.
Regardless of their answers, the students were randomly told their performance was "terrible" (to put them in a bad mood) or "excellent" (to put them in a good mood).
All participants were asked to review what they were told was a new social networking site called SocialLink. The overview page presented preview profiles of eight individuals, which the students could click on to read more.
The key to the study was that the eight profiles were designed to make the people profiled appear attractive and successful - or unattractive or unsuccessful.
Each profiled person was ranked on a scale of 0 to 5 on both career success (number of dollar signs next to their profile) and attractiveness, or "hotness" (number of hearts).
The profile images were blurred so that participants could not see what they actually looked like.
Overall, the researchers found that people tended to spend more time on the profiles of people who were rated as successful and attractive.
But participants who had been put in a negative mood spent significantly more time than others browsing the profiles of people who had been rated as unsuccessful and unattractive.
"One of the great appeals of social network sites is that they allow people to manage their moods by choosing who they want to compare themselves to," Knobloch-Westerwick said.
The study was published in the journal Computers in Human Behaviour.