I do this.
I have a rental property, have a line of credit and keep 10-15k in there. When it is built up enough I invest into individual shares. This allows me to offset the interest expense on my share portfolio as part of my overall investment strategy.
I'll continue doing this for many, many years as I see it as a great way to build my net worth. I also really enjoy the process, investigation and monitoring of the stock market and I've done quite well out of it. Much better than just paying back the mortgage and not investing elsewhere.
As long as you know what you are doing, it works out better off.