Bonnie McKee hopped on TikTok to reveal how Katy Perry inadvertently helped her write "Hold It Against Me" for Britney Spears.

The songwriter and "American Girl" singer has amassed an extensive portfolio crafting hits for the likes of Perry, Spears, Kesha, Adam Lambert and Christina Aguilera. She previously spilled tea about working with Perry on songs such as "Teenage Dream" and "Roar" while breaking them down on TikTok.

In her latest behind the scenes video, however, McKee revealed that she was working on Teenage Dream at the same time she was writing songs for Spears' seventh album, Femme Fatale.

When it came to "Hold It Against Me," McKee said she had an "amazing" melody. The lyrics weren't there yet, though. She knew she wanted to put a spin on a cheesy pick-up line but couldn't settle on one that really worked.

Then Perry entered the studio and changed the trajectory of a promising future bop.

"Katy Perry walked in, and she looked bomb as f--k," McKee said. "I was like, 'D--m Katy, if I told you had had a nice body, would you hold it against me?' And then I was like... 'I gotta go.'"

"Once I had that concept, it kind of just wrote itself," she added. McKee showed some of the original lyrics she was toying with and sang a couple bars of the iconic track.

Her notebook of lyrics is filled with the equivalent of pop gold. Check it out the in the TikTok below.

McKee's witty lyricism paid off. "Hold It Against Me" debuted at the top spot on the Billboard Hot 100 in 2011. The dubstep-inspired hit became Spears' fourth song to top the chart.

Not only that, but it made her the second artist to debut at number one on the Hot 100 more than once. At that point the only other artist to pull off the feat was Mariah Carey. Billboard noted that it also netted her what was then the highest first week sales for a female artist.

Want another fact in Spearstory (the history of Britney Spears)? The song placed Spears in an exclusive group of artists who have managed to top the Billboard Hot 100 in three different decades.

"...Baby One More Time," her debut single, went number one in the '90s. "Womanizer" and "3" topped the chart in the '00s. "Hold It Against Me" and a remix of Rihanna's "S&M" featuring Spears reached the pinnacle position in the '10s.

Interestingly, this isn't the only time Perry and Spears have shared musical space, either. Spears recorded a song called "Ooh La La" for the soundtrack for The Smurfs 2, which Perry starred in.

Perry, meanwhile, co-wrote a song called "Passenger" with Sia, which wound up on Spears' eighth album Britney Jean. A demo of Perry singing the confessional song leaked years after Spears' version dropped.

Songs Artists Regret They Recorded

More From Mix 94.1