For the basic tooltip, you want:
<div title="This is my tooltip">
like:
.visible {
height: 3em;
width: 10em;
background: yellow;
}
<div title="This is my tooltip" class="visible"></div>
For a fancier javascript version, you can look into:
https://jqueryhouse.com/best-jquery-tooltip-plugins/
The above link gives you 25 options for tooltips.
The placement of the tooltip is controlled by a jQueryUI Position object and the default settings are:
{ my: "left+15 center", at: "right center", collision: "flipfit" }
The Position Object, in particular the collision
attribute can be changed to force placement of the control somewhere else. The default for tooltips is flipfit which means the if the default (on the right) does not fit it will flip to the left and try that position and if that doesn't collide with anything, try to fit the control by moving it away from the edge of the window. The result is that it now collides with the <input>
. There doesn't seem to be an option to force a long tooltip to cleverly wrap.
However there are two ways to wrap the content:
Add a custom CSS class to the configuration with a max-width
to force wrapping, for example:
JavaScript
$('input').tooltip({
tooltipClass:'tooltip'
});
CSS
.tooltip {
max-width:256px;
}
Or insert hard line-breaks <br/>
in the title attribute, for example
title="Lorem ipsum dolor sit amet,<br/>consectetur adipisicing elit"
Edit: So it looks like jQueryUI changed the tooltip content option between v1.9 and v1.10 (according to the changelog). For reference here is the difference:
v1.9.2
content: function() {
return $( this ).attr( "title" );
}
v1.10
content: function() {
// support: IE<9, Opera in jQuery <1.7
// .text() can't accept undefined, so coerce to a string
var title = $( this ).attr( "title" ) || "";
// Escape title, since we're going from an attribute to raw HTML
return $( "<a>" ).text( title ).html();
}
So you can put back the older functionality that does not escape <br/>
tags in the title attribute by using the .tooltip()
like this:
$('input').tooltip({
content: function() {
return $(this).attr('title');
}
});
Also, see jsFiddle demo.
Best Answer
Set theAutoPopDelay
property to be something higher - it defaults to 5000 (5 seconds)Update: My mistake:
So you can't get the tool tip to be displayed for longer than 5 seconds using this method - instead you need to use the Show to explicitly show the tool tip when the user hovers over the picturebox. Just replace your call to
SetToolTip
with one toShow
in yourMouseHover
event handler: