show that continuous maps preserve connectedness

Hi guys.

Suppose we have two metric spaces $\displaystyle X$ and $\displaystyle Y$, and we have a function $\displaystyle f:X\to Y$ which is continuous on $\displaystyle X$. If $\displaystyle S$ is a connected subset of $\displaystyle X$, then it's easy enough to show that $\displaystyle f(S)=\{f(x):x\in S\}$ is connected.

However, suppose there is a function $\displaystyle g:X\to Y$ which is only continuous on $\displaystyle S$, but not necessarily the rest of $\displaystyle X$. How do we show that $\displaystyle g(S)$ is connected?

Any help would be much appreciated. Thanks!