Skip to content

Instantly share code, notes, and snippets.

@amithegde
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amithegde/9420197 to your computer and use it in GitHub Desktop.
Save amithegde/9420197 to your computer and use it in GitHub Desktop.
jQuery UI Tooltip which lets the user to interact with the tooltip such as copy text from the tooltip
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Tooltip - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css">
<script>
$(function() {
$( '.tooltip' ).tooltip({
open: function(){
// make sure all other tooltips are closed when opening a new one
$('.tooltip').not(this).tooltip('close');
}
}).on('mouseleave', function(e){
var that = this;
// close the tooltip later (maybe ...)
mouseLeaveTimer = setTimeout(function(){
$(that).tooltip('close');
}, 100);
// prevent tooltip widget to close the tooltip now
e.stopImmediatePropagation();
});
$(document).on('mouseenter', '.ui-tooltip', function(e){
// cancel tooltip closing on hover
clearTimeout(mouseLeaveTimer);
});
$(document).on('mouseleave', '.ui-tooltip', function(){
// make sure tooltip is closed when the mouse is gone
$('.tooltip').tooltip('close');
});
});
</script>
<style>
label {
display: inline-block;
width: 5em;
}
</style>
</head>
<body>
<input id="age" class="tooltip" title="We ask for your age only for statistical purposes.">
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment