What story format are you using? Sugarcube, Harlowe,...?
In Sugarcube, when I need to use a Sugarcube variable in a HTML element, I use the <<print>> macro to print what would be the HTML code with the variables:
<<print '<a title="' + $tooltip + '">' + $text + "</a>">>
If you are using other format, I'm not sure if its print function will allow this.
(I think it's called the "Stupid Print Trick" xD)