I need basic idea of creating a custom tooltip using pure Javascript
code;
What I want :
For example :
<a href="#" onmousemover="tooltip('text')">Link Text</a>
And onmouseover
I want to display a custom tooltip with fixed position
based on <a>
's element position
, to start from right:0
or from left:0
of the <a>
element;
As this question comes up when a user searches for
custom tooltip
, I would like to add the bootstrap's JS tooltip, although you have mentioned pure javascript. So in a sense this answer is only to give the future readers another nice option to work with.Take a look here for how to use bootstrap tooltip plugin. And here to learn about the options and methods available at your disposal when using Bootstrap's JS Tooltip.
Still I am giving the
tryit
from their site here:P.S.: Before you downvote for this answer not being an answer to the OP, please note that I intended this to be of help to future readers only, since a search for
custom tooltip
leads here.I have a great idea about this question.
HTML
JavaScript
By including this script into your page, you just have to use
tooltip="Text"
in any HTML ElementCSS
You can edit CSS as your wish!
Here's my JSFiddle
Hope this will help you.
You need a function something like this:
Where
ttdiv
is the id of the tooltip div, that is initially set todisplay:none
. You'll need an accompanyinghide()
function to hide the tooltip whenonmouseout
is triggered.Here's a working JSFiddle.