I have an SVG with a title element, as well as polygons with their own empty titles in the hopes of preventing the parent title from appearing when hovering over the polygons because I have a custom JavaScript tooltip for the polygons. So something like
<svg aria-labelledby="title1">
<title id = "title1">My big title</title>
<polygon aria-labelledby="title2"></polygon>
// this title element is dynamically generated by JS after the rest of the SVG is added to page
<title id="title2"></title>
</svg>
The SVG is generated dynamically from a library and I use JavaScript to append the blank title to remove the main title tooltip from polygons, but after running the JavaScript the tooltip still appears even though the new blank titles are in the DOM.
If I go into the developer tools and edit HTML, but make no changes and then hover over the polygons only the custom tooltip displays as expected. It seems that the JavaScript code adds the blank titles but the browser is cacheing the previous aria data state. Is there any way to use JavaScript to force the browser to reevaluate the aria metadata? I’ve tried basic things like adding and removing classes
2
Answers
You can reinsert the SVG in the dom:
Or do remove and add on the parent.
A minimal reproducible would be nice for further investigation.
There seem to be two misunderstandings in the question, if I got the question right.
aria-labelledby
do not change browser behaviour like tooltips. They only control what gets exposed to assistive technology via the accessibility tree.<title>
attributes inside one element¹.To give a SVG graphics element a title, the
<title>
element needs to be it’s child.I also recommend leaving out the
aria-labelledby
attribute for the SVG document, it’s redundant, as the title’s very purpose is to provide an accessible name already.<title>
siblings only in a single case:—the SVG specification