I need help creating HTML with tooltips and tooltip text for each <p>
tag. While I know this can be achieved using d3, I am currently using a CSS approach because it feels more familiar to me.
In an ideal scenario, the desired HTML output should resemble the following structure:
<p class="tooltip" style="font-size: 73.6207pt;">eyes.
<span class="tooltiptext">Tooltip text</span>
</p>
<br>
<p class="tooltip" style="font-size: 73.6207pt;">eyes.
<span class="tooltiptext">filler text</span>
</p>
To prevent the text inside the p
tags from appearing on the same line, I have included a <br>
. However, the issue arises when the <br>
becomes nested within the span tags, resulting in an undesirable HTML structure as shown below.
<p class="tooltip" style="font-size: 73.6207pt;">eyes.
<span class="tooltiptext">Tooltip text <br></span>
</p>
<p class="tooltip" style="font-size: 73.6207pt;">eyes.
<span class="tooltiptext">filler text <br></span>
</p>
The current d3 code snippet is as follows:
Despite attempting to rearrange the .append("d3")
, I have encountered challenges where it either disrupts the tooltip functionality or interferes with the visualization entirely.
div.selectAll(null)
.data(myData)
.enter()
.append("p")
.attr("class", "tooltip")
.text(function(d) {
return d.word;
})
.style("font-size", function(d) {
return scale(parseInt(d.score)) + "pt";
})
.append('span')
.attr("class", "tooltiptext")
.text("filler text")
.append("br")
Your assistance in resolving this matter is greatly appreciated.