In the answer I gave here, I exhibit a bijection $(0,1)\to\Bbb R$. Note that the numerator runs linearly from $-1$ to $1$, while one linear factor in the denominator runs from $0$ to $1$ and the other runs from $1$ to $0$. As we approach the lower bound of the domain, the function tends to $-\infty$; the upper bound, to $+\infty.$ Our choice of factors also makes injectivity and continuity easy to prove.
Something similar can be done for an arbitrary interval $(a,b).$ Put a factor $x-a$ and a factor $b-x$ in the denominator, then make the numerator $2x-(a+b)$. You can scale it however you like.
Your example certainly does the trick, too, and an appropriate transformation will adapt the example to any interval. If you want some help visualizing why your example should work, see the picture in this question, replacing $h$ by $\pi x$. As we allow $x$ to range over $(-\pi/2,\pi/2)$, it becomes readily apparent that the signed length of that long opposite leg takes on every real value, and that to each signed length corresponds a unique $x$ in that range. Thus, $\tan(\pi x)$ is a bijection, so since $x\mapsto -x$ is a bijection, then your example works.