Throughout Dwight's job at Dunder Mifflin. Even though the Scranton office is anything but professional, Dwight still manages to harass his coworkers, and Jim manages to make a fool out of Dwight every chance he gets. The animosity that is then created might appear severe, but that isn't necessarily the full story.
Despite the ever-changing landscape in Dunder Mifflin's Scranton branch, two things remain consistent: Dwight's lack of respect for his fellow coworkers, and Jim's array of pranks on his desk mate, Dwight. At times, both paper salesmen flirt with crossing the line when it comes to their antics and often definitely do end up crossing the line. Whether it's Dwight putting down his coworkers and assuming a position of power over them, or Jim putting Dwight's life at risk for a laugh, the two should, therefore, cause tension in the workplace. However, due to the specific nature of Jim and Dwight's dynamic in The Office, coupled with the very causal makeup Michael Scott has instilled in the workplace, something unexpected ends up happening instead.
Jim's pranks, regardless of how belittling and dangerous they are, could end up being the reason Dwight never gets laid off. The number of complaints about Dwight is seemingly unparalleled during The Office's 201 episodes–and in season 5, episode 14, "Stress Relief," Dwight actually does end up getting fired as a result of his office behavior during one of his so-called safety drills. Nevertheless, the outlandish and public nature of Jim's pranks knocks Dwight off his high horse and allows the other Scranton branch office to put aside their grievances with Dwight and get a kick out of his comeuppance.
The relationship between John Krasinski's and Rainn Wilson's characters in the Scranton office is so well-worn that Jim almost seems to anticipate Dwight's moods and often pranks him before Dwight has a chance to sour anyone's day. For instance, in The Office season 2, episode 6, "The Fight," the episode opens with Jim putting Dwight's desk in the bathroom before later taking Dwight's purple belt when Dwight says something less than savory. These public pranks create a more lighthearted feeling in an office environment that otherwise could be seen as hostile because of Dwight. They perpetuate the idea that nothing that happens in the Scranton branch has any actual severity; therefore, rendering Dwight as something to laugh at and not hold hostility toward.
Jim's emotional maturity and people skills are the counterweights to Dwight's social ineptitude. Even though the two may appear to hate each other (and Dwight would argue that he definitely hates his coworker), Jim does appear to look out for Dwight's well-being and best interests, as well as his other coworkers in The Office. Jim's barrage of pranks on Dwight goes further than his own amusement; they are a way for the Dunder Mifflin employees to find something of joy in their dreadfully mundane office setting.