I'm asking this because I've seen contradictory answers in different textbooks.
On one hand, $\frac{1}{\tan\left(x\right)}$ is undefined for $\tan(x)=0$, but $\tan(x)$ itself is undefined for $x=\frac{\pi}{2}$. So, in this view, the domain should be $\mathbb{R}\backslash \left\{\frac{\pi }{2}n,\:n\in \mathbb{Z}\right\}$.
On the other hand, $\frac{1}{\tan\left(x\right)}$ can also be written as $\frac{\cos\left(x\right)}{\sin\left(x\right)}$, and this is only undefined when $\sin\left(x\right)=0$
The first answer is correct. $\tan x = \frac{\sin x}{\cos x}$ and so $\frac{1}{\tan x}$ can be written as $\frac{\cos x}{\sin x}$ provided you can actually take the reciprocal of both sides of the original equation. If they are undefined, like when $x = \frac{\pi}{2}$, taking the reciprocal is not a legal operation so the identity breaks down. It is true that $\lim_{x \rightarrow \frac{\pi}{2}}\frac{1}{\tan x}$ is defined and it's equal to $\frac{\cos \frac{\pi}{2}}{\sin \frac{\pi}{2}}$.