Slash Coding

  • Android Development
  • CSS
  • Subscribe
  • About Us
  • Contact Us
You are here: Home / Web Development / jQuery / Creating a stylish jQuery Tooltip using a Plugin

Creating a stylish jQuery Tooltip using a Plugin

By Aneesh Bhatnagar

I can bet that you have seen a tooltip on almost every page that you visit. Web developers may know this by the name of a title attribute for an element. The value for the title is displayed as a tooltip on HTML browsers. For instance, if you hover on any image on Slash Coding, you will see what the image is in the form of a simple tooltip. But today, I will provide you a simple guide which will help you create a customized, stylish jQuery tooltip using a jQuery plugin. You may hover on this image, and you will get a simple HTML tooltip showing you the title of that image.

jQuery Tooltip Example

DEMO | DOWNLOAD

If you are reading this article, chances are that you are interested in jQuery. You might want to try the following tutorials as well.

  • Learn how to create a Sticky Menu using jQuery
  • Learn how to create a custom Content scroller using jQuery
  • Create a jQuery based full page loading animation

Now, without wasting any time, let’s get started with the tutorial.

HTML Part

In the HTML part, we just need to create a mock-up page which will display the jQuery tooltip when hovered on. For this, I will create 2 different span tags, that will show a tooltip at the top and bottom respectively. To do that, create a new page and paste the following contents on to that page.


<html>
<head>
<title>jQuery tooltip by Slash Coding </title>
</head>
<body>
<h1>jQuery Tooltip Demo by Slash Coding</h1>
<span title="This is a normal tooltip">Hover here for a simple Tooltip</span>
<h2>This is an interesting page, and here we will learn how to create a jQuery customized tooltip for our text.</h2>
<p><span id="top-tooltip">Hover here for a tooltip on the top of the element</span></p>
<p><span id="bottom-tooltip">Hover here for a tooltip on the bottom of the element</span></p>
</body>
</html>

CSS Part

For the CSS part, I am not going to style the webpage we just created, but we need to import the CSS for the jQuery tooltip plugin. For doing that, head over to the official plugin webpage and download the package. When you download it, extract it. There will be a folder named CSS. Just copy the entire folder into your workspace (the place where you just created the above HTML file).

Next, just reference the CSS stylesheet from your HTML page, by adding the following line of code to the head tag of your page.


<link rel="stylesheet" type="text/css" href="css/tooltipster.css" />

jQuery Tooltip Plugin

Now, our last and final job is to implement jQuery, and import the jQuery tooltip plugin on your webpage. First of all, copy the “jquery.tooltipster.min.js” file from the js folder of the ZIP file that you just downloaded. Create a folder named js in your workspace, and paste it there. Next, we need to link this file and the jQuery file to our webpage. To do that, place the following code just before closing the body tag on your webpage. Note that you can also place this code in the head section of your website as well, but it would impact website loading time.


<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.0.min.js"></script>
<script type="text/javascript" src="js/jquery.tooltipster.min.js"></script>
<script>
$(document).ready(function() {
$('#top-tooltip').tooltipster({
content:$('<p>This is an example of a tooltip on the top of the element</p>'),
minWidth:150,
maxWidth:150,
position: 'top'
});
$('#bottom-tooltip').tooltipster({
content:$('<p>This is an example of a tooltip on the bottom of the element</p>'),
minWidth:250,
maxWidth:250,
position: 'bottom'
});
});
</script>

In the above mentioned code, I have set the minWidth and maxWidth parameters of the tooltip to get a fixed width tooltip. You can change these values as you like, and the position parameter just defines the position of the tooltip, top or bottom. There are a lot more parameters that you can specify. Check the official plugin page for those parameters.

DEMO | DOWNLOAD

Well, that’s it. You just created yourself a good looking jQuery tooltip. Go ahead and share this tutorial with your friends and let them know about it as well. Don’t forget to subscribe to Slash Coding for latest post updates via RSS Feeds, Facebook, Google+ or Twitter.

Did you enjoy this article?
Subscribe to our email alerts when we post something new so you don't miss out.

About Aneesh Bhatnagar

Aneesh Bhatnagar is a freelance web developer, who specializes in front-end website development with HTML5, CSS3 and jQuery. He believes in transforming the entire web into a Responsive Web. He also specializes in use of Bootstrap framework to get websites up and running.

Comments

  1. joseph says

    November 12, 2014 at 6:37 am

    beautiful tooltip in the demo. Can the color be changed? gray is a bit boring

    • Aneesh Bhatnagar says

      November 12, 2014 at 5:09 pm

      Yes, you can change the color as you like.. Head over to the official theme page for more details on the theme.

      http://iamceege.github.io/tooltipster/#options

  2. subhrajit says

    December 9, 2014 at 12:29 pm

    it is not downloaded… I need .js file.

    • Aneesh Bhatnagar says

      December 10, 2014 at 12:53 am

      Hey Subhrajit,

      You can try downloading from the official website mentioned in the tutorial above, or you can download the demo I have uploaded, and use the JS files from there! 🙂

Search Slash Coding

Follow Us

RSS Feeds Facebook Twitter Follow Google+

Categories

  • Android Development
  • C++
  • Developer Tips
  • Slash Coding
  • Web Development
    • CSS
    • JavaScript
    • jQuery
    • PHP

Recently Published

  • Moving Ahead from Front End and Android Development
  • How to Export a Project from Android Studio
  • What is jQuery? Let’s Answer this Common Question today!
  • Mobile App Prototyping : Pixate Studio
  • How to Create a Countdown Timer using jQuery

Subscribe to Email Alerts

Eager to learn more from Slash Coding?
Sign up for daily email updates when anything new comes up. Get it straight in your inbox.

Follow Us on Social Media

RSS Feeds Facebook Twitter Follow Google+

Copyright © 2025 · Slash Coding · Powered by the Genesis Framework
Sitemap | Privacy Policy | About | Contact

×
Get Notified of the new Tutorials when they are posted!
Never miss any article update from Slash Coding. Subscribe to email alerts today!