I try to use tippy in an object SVG tag text, but when I hover the text tag I receive this error:
Uncaught TypeError: Cannot read properties of null (reading 'body')
I try also to append on a document.body but doesn't solve a problem.
how can i display the tooltip in an object svg text?
// error message
getScrollParent.js:8 Uncaught TypeError: Cannot read properties of null (reading 'body')
at getScrollParent (getScrollParent.js:8:1)
at getScrollParent (getScrollParent.js:15:1)
at getScrollParent (getScrollParent.js:15:1)
at listScrollParents (listScrollParents.js:19:37)
at Object.setOptions (createPopper.js:69:120)
at createPopper (createPopper.js:215:1)
at createPopperInstance (tippy.esm.js:1167:43)
at mount (tippy.esm.js:1204:1)
at Object.show (tippy.esm.js:1450:1)
at scheduleShow (tippy.esm.js:1240:1)
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<link
rel="stylesheet"
href="https://unpkg.com/tippy.js@6/animations/scale.css"
/>
<script src="https://unpkg.com/@popperjs/core@2"></script>
<script src="https://unpkg.com/tippy.js@6"></script>
</head>
<body>
<div class="container">
<object id="svgObject" class="atac-svg-tranlator" data="./src/assets/images/test.svg" type="image/svg+xml" width="800" height="1100"></object>
</div>
<script>
document.addEventListener('DOMContentLoaded', function() {
const svgObject = document.getElementById('svgObject'); // Select the <object> element
svgObject.addEventListener('load', function() {
const svgDoc = svgObject.contentDocument; // Get the SVG document from the object element
if (svgDoc) {
// Find and initialize tooltips for text elements within the SVG
const textElements = svgDoc.querySelectorAll('text');
textElements.forEach(function(textElement) {
// Create Tippy tooltip for each text element
tippy(textElement, {
content: textElement.textContent,
appendTo: svgDoc.documentElement,
placement: 'top',
});
});
} else {
console.log('SVG document not loaded');
}
});
// Optionally, you can add further code here
});
</script>
</body>
</html>
The svg inside file it is simple like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="500" height="1100">
<text x="50" y="50">ciao come</text>
<text x="70" y="80">test test testo 3</text>
<text x="30" y="130">origin pixels size off jira</text>
<text x="90" y="160">svg body testo 4</text>
<text x="50" y="180">lorem ipsum testo 5</text>
<text x="80" y="210">silente testo 3</text>
</svg>