I know that d3 renders elements based on the called order. So if I want to render white text over a black rectangle, I can just call the rect first and then call the white text.
However, in my particular case, my rect's dimension is based on the my white text, so I have to call the white text first.
A go-around I found was to use the use tag, but I couldn't get it to work, here's my current attempt:
the text:
var textToolTip = gToolTip
.append("text")
.attr("id", "toUse")
.text(.....)...
the use tag:
var useText = gToolTip.append("use").attr("xlink:xlink:href", "#toUse");
I have also tried to give textToolTip xlink:href but it didn't work. For use tag, I have tried to use xlink:href instead of xlink:xlink:href, it didn't work. I am using double xlink because of this answer I found: How do I define an SVG doc under <defs>, and reuse with the <use> tag?