Official website for Web Designer - defining the internet through beautiful design
FOLLOW US ON:
Author: Mark Billen
2nd August 2010

Adding jQuery tooltips

Well-designed pop-up tooltips provide useful additional sign-posting information about the content on your website, and where a link will take you…

08 Add some style

We’ve got the default appearance just now, but we don’t have to stick with that. There are several built-in styles we can take advantage of, or we can build our own styles. Let’s start with the built-in styles. Change your code to read as follows:

<script type=”text/javascript”>
$(document).ready(function()  {
$(“a”).qtip(    {
content: ‘This is a qTip pop-up’,
position: {
corner: {
target: ‘topRight’,
tooltip: ‘bottomLeft’
}
},
style: {
name: ‘dark’
}
});
});
</script>

09 Other style options

Your tooltip is now a shade of dark grey. Other options built into the plug-in include red and blue. Creating your own styles is as simple as specifying values for the different attributes such as border width, background colour and so on. Change your code to read as below:

<script type=”text/javascript”>
$(document).ready(function()  {
$(“a”).qtip(    {
content: ‘This is a qTip pop-up’,
position: {
corner: {
target: ‘topRight’,
tooltip: ‘bottomLeft’
}
},
style: {
width: 200,
padding: 5,
background: ‘#A2D959’,
color: ‘black’,
textAlign: ‘center’,
name: ‘dark’
}
});
});
</script>


10 Defining inheritance

Adding jQuery tooltips

You will have noticed that we still specified the dark theme at the end of the previous block of code. This
acts as a kind of fall back inheritance option – anything that we haven’t specified style-wise is picked up from
the dark style. This is particularly useful as we can build our styles using the built-in options as a template to
start from.

11 Replace the title attribute

Adding jQuery tooltips

Up until now we’ve been passing in content to our tooltips, but really the most useful functionality qTip offers is the ability to make more of the humble title attribute. Thankfully it’s really easy to get the tooltip content from the title attribute of a link. Alter your code so that it looks like the code below:

<script type=”text/javascript”>

$(document).ready(function()  {
$(“a”).qtip(    {
content: {
text: false
},
position: {
corner: {
target: ‘topRight’,
tooltip: ‘bottomLeft’
}
},
style: {
width: 200,
padding: 5,
background: ‘#A2D959’,
color: ‘black’,
textAlign: ‘center’,
name: ‘dark’

}
});
});
</script>

12 Degrade gracefully

Adding jQuery tooltips

The primary consideration when adding aesthetic polish to a piece of content that conveys important information is how that degrades if the browser has JavaScript disabled, or styles turned off. Thankfully with the code we’ve just created the browser will revert to standard HTML title tags and tooltips, so we’ve got code that degrades nicely.

13 Rounded corners and tips

We’ve barely touched on all the options available within the qTip framework. Experiment with the code below to set border width, rounded-corner radius, create a speech-bubble tip and more:

<script type=”text/javascript”>
$(document).ready(function()  {
$(“a”).qtip(    {
content: {
text: false
},
position: {
corner: {
target: ‘topRight’,
tooltip: ‘bottomLeft’
}
},
style: {
width: 200,
padding: 5,
background: ‘#A2D959’,
color: ‘black’,
textAlign: ‘center’,
border: {
width: 3,
radius: 8,
color: ‘#6699CC’
},
tip: ‘bottomLeft’,
name: ‘dark’
}
});
});
</script>

Pages: 1 2 3

  • Tell a Friend
  • Follow our Twitter to find out about all the latest web development, news, reviews, previews, interviews, features and a whole more.

    16 Comments »

    • Sonali Agrawal said:

      Awesome tip..Simple and clear! Thanks…

    • Alan.. said:

      Great little tutorial, easy, well written and clear to understand. I will be definitely try to include this into one of my future designs. Thanks very much.

    • WebProject said:

      Great Article!

      Thank you for sharing it…

    • SearchEngenie said:

      Another generic comment to add to the list.

      Thanks!

    • warzenie piwa said:

      hi

      Overall, great! But keep in mind one thing, when copying code from the site and it doesn’t work, pay attention to the quotation marks. Once rewritten, works great. cheers :-)

    • Everton Vianna Arquiteto de Informação & Web Designer said:

      Very good. Add Favorites.

    • Doug H said:

      Man, no matter what I do, can’t get this to work at all….bummer.

    • Steve Kramer said:

      Great little tooltip function, does not work with jquery 1.4.2 with sizzle unfortunately as this is surely a must for CS3??!!

    • Christopher Hill said:

      Try out ChillTip jQuery PlugIn. It is light weight easy to install and easy to customise.

    • Web Designer said:

      Great article, thanks for sharing. I need to try these tooltips on my website!

    • pathon said:

      Hi mate it not working..!

    • webmaster said:

      Nice Articles thanks for sharing this.

    • Maoelana Noer M said:

      that is awesome. nice tutorial. I will try it.

    • Rob said:

      Nice, here is another tooltip to try: http://www.websanova.com/plugins/websanova/tooltip

    Trackbacks

    What's your opinion?

    Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

    Be nice. Keep it clean. Stay on topic. No spam.

    * Required fields