Showing a tooltip on hover based on a tooltip attribute
Don't do anything in JavaScript that can be done with just CSS!  The :hover pseudo-class is perfect for tooltips.  Use ::after to append a pseudo-element with the tooltip content, where the content is specified by the content property.



div[tooltip]:hover::after {
    content: attr(tooltip);
    display: block;
    position: absolute;
    transform: translateX(-50%);
}

/* Don't review this CSS; it was added just for the demo. */
div[tooltip] { width: max-content; margin: auto; }
&lt;div class="example" tooltip="Hello World"&gt;Hover me.&lt;/div&gt;