As the title states, how can I display a tooltip message on hover using jQuery?
-
1Unless it is a dynamically generated element or a tooltip whose contents might change, I would suggest using the `title="My tooltip` attribute with the element itself – Sudipta Chatterjee Mar 24 '13 at 02:37
-
please refer i have tested it work flawless : http://stackoverflow.com/questions/11781665/how-to-show-a-simple-textbox-when-i-hover-over-an-icon-using-jquery – Develop4Life Jun 06 '13 at 13:43
9 Answers
Tooltip plugin might be too heavyweight for what you need. Simply set the 'title' attribute with the text you desire to show in your tooltip.
$("#yourElement").attr('title', 'This is the hover-over text');

- 38,153
- 34
- 100
- 135
-
11Note that you can also place your tooltip in the attribute directly in the HTML: – Mark Brittingham Jun 24 '12 at 14:47
-
4This didn't work for me in IE! Had to use `prop` instead. `$("#yourElement").prop('title', 'This is the hover-over text');` – SNag Dec 06 '13 at 05:48
-
Following will work like a charm (assuming you have div/span/table/tr/td/etc with "id"="myId"
)
$("#myId").hover(function() {
$(this).css('cursor','pointer').attr('title', 'This is a hover text.');
}, function() {
$(this).css('cursor','auto');
});
As a complimentary, .css('cursor','pointer')
will change the mouse pointer on hover.

- 795
- 7
- 26
take a look at the jQuery Tooltip plugin. You can pass in an options object for different options.
There are also other alternative tooltip plugins available, of which a few are
Take look at the demos and documentation and please update your question if you have specific questions about how to use them in your code.

- 124,184
- 33
- 204
- 266
As mentioned in most of the answers the uses of plugins would be heavy compared with the requirements here. which is why here's another solution to get the required output just with simple HTML, CSS & JQuery code.
using CSS will give us a better view, check the code below
$(".tool-tip").attr('title-new', 'another example to display the hover-over texts');
button {
background: aqua;
padding:10px;
}
.tool-tip[title-new]:hover:after {
content: attr(title-new);
position: absolute;
border: #c0c0c0 1px dotted;
padding: 10px;
display: block;
z-index: 100;
background-color: #000000;
color: #ffffff;
max-width: 200px;
text-decoration: none;
text-align:center;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>hover on the button below to check the results</p>
<button class="tool-tip">Here I am</button>

- 875
- 5
- 21
Take a look at ToolTipster
- easy to use
- flexible
- pretty lightweight, compared to some other tooltip plugins (39kB)
- looks better, without additional styling
- has a good set of predefined themes
You can do it using just css without using any jQiuery.
<a class="tooltips">
Hover Me
<span>My Tooltip Text</span>
</a>
<style>
a.tooltips {
position: relative;
display: inline;
}
a.tooltips span {
position: absolute;
width: 200px;
color: #FFFFFF;
background: #000000;
height: 30px;
line-height: 30px;
text-align: center;
visibility: hidden;
border-radius: 6px;
}
a.tooltips span:after {
content: '';
position: absolute;
top: 100%;
left: 35%;
margin-left: -8px;
width: 0;
height: 0;
border-top: 8px solid #000000;
border-right: 8px solid transparent;
border-left: 8px solid transparent;
}
a:hover.tooltips span {
visibility: visible;
opacity: 0.8;
bottom: 30px;
left: 50%;
margin-left: -76px;
z-index: 999;
}
</style>

- 10,136
- 1
- 57
- 42