If you want to enhance the user experience of your website by adding tooltips to links, you can use jquery.tooltipster.js. In this article, we will introduce how to use jquery.tooltipster.js to display the text set in the title attribute of a link tag as a tooltip when you mouse over it.
Setting Up the CSS File for Displaying Tooltips on Links
First, set up the necessary CSS file to display tooltips on links. The following stylesheet loads the tooltipster.css file, which can be customized as needed.
<style type="text/css" media="all">
<!--
body{
margin:0;
padding:0;
}
h1{
text-align:center;
font-size:18px;
font-weight:bold;
padding:10px 0;
line-height:1.4em;
text-align:center;
}
.clWrap{
width:800px;
margin:0 auto;
text-align:center;
}
a{
font-size:18px;
text-decoration:none;
}
a:hover{
text-decoration:underline;
}
-->
</style>
<link rel="stylesheet" type="text/css" href="tooltipster.css" />
This CSS file is used to adjust the styling of each element and customize the appearance of the tooltip.
Setting Up JavaScript to Display Tooltips Using jQuery
Next, set up the JavaScript to display tooltips on links using jQuery. The following code loads the jquery-1.9.0.min.js and jquery.tooltipster.js files and applies the .tooltip() function to link tags.
<script type="text/javascript" src="jquery-1.9.0.min.js"></script>
<script type="text/javascript" src="jquery.tooltipster.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('.tooltip').tooltipster();
});
</script>
This code is executed after the document is loaded and adds the tooltip feature to link tags with the class “tooltip.”
Setting Up HTML to Display Tooltips on Links
Next, set up the link tag for which you want to display the tooltip. The following HTML code sets the text to be displayed in the title attribute of a link tag with the class “tooltip.”
<div class="clWrap">
<h1>When you mouse over the link below, the text set in the title attribute of the link tag will be displayed as a tooltip.</h1>
<a href="/" class="tooltip" title="A web technology media to enhance the value of fathers with the theme of 'Making life easier for all fathers.'">DAD UNION</a>
</div>
With this setup, when you mouse over a specific link, a tooltip is displayed, showing the content of the link.
jquery.tooltipster.js: Demo Page for Displaying Tooltips on Links
If you want to try out the tooltips, check out the demo page below.
jquery.tooltipster.js: Tooltip Demo
On this demo page, you can see a concrete example of using jquery.tooltipster.js to display tooltips on links.
Source: Tooltipster – The jQuery Tooltip Plugin
Tooltipster – The jQuery Tooltip Plugin
This completes the detailed guide on how to use jquery.tooltipster.js to display tooltips on links. Try using this technique to enhance the user experience and make information more accessible.
※ Please use it at your own risk. Do not reuse the Google Analytics tags in the demo page tags.