This notation is often difficult to make sense of. What, for instance, would it mean to differentiate $\sin(x)$ with respect to $\cos(x)$? To begin with, we must write $\sin(x)$ in terms of $\cos(x)$:
$$
\sin(x)=\sqrt{1-\cos(x)^2} \, ,
$$
ignoring the $\pm$ signs that should be on the square root for now. This means that
$$
\frac{d\sin(x)}{d\cos(x)}=\frac{d\sqrt{1-\cos(x)^2}}{d\cos(x)} \, .
$$
But this is the same as
$$
\frac{d}{du}\left(\sqrt{1-u^2}\right)\Biggr|_{u=\cos(x)} \, .
$$
So every time you see
$$
\frac{df(x)}{dg(x)} \, ,
$$
note that $f(x)=h(g(x))$ for some function $h$, and write
$$
\frac{dh(g(x))}{dg(x)}=\frac{dh(u)}{du}\Biggr|_{u=g(x)} \, .
$$
The $u$ is a dummy variable that can then be replaced by whatever function you are 'differentiating with respect to'. You can use $g(x)$ as a dummy variable, but it often leads to confusion, and is considered by many people to be poor style.
To give another example, let's consider the chain rule,
$$
\frac{dy}{dx}=\frac{dy}{du} \cdot \frac{du}{dx}
$$
Say $y=\sin(u)$, where $u=x^2$. Then, the chain rule appears to say
$$
\frac{d}{dx}(\sin(x^2))=\frac{d}{dx^2}\left(\sin(x^2)\right) \cdot \frac{d}{dx}(2x) \, .
$$
It seems difficult to parse the first term on the RHS. The easiest way to do this is to write it instead as
$$
\frac{d}{du}(\sin(u)) \Biggr|_{u=x^2} \, .
$$
However, we can also treat $x^2$ just as we would any other variable, and make sense of the term that way, too.