Overview

It's a simple jQuery tooltip plugin extended from Twitter Bootstrap's tooltip plugin that support 4 positions, background color, font color and border color without using images.

Data Attributes "data-"

You can use the HTML5 data- attributes (provided in the API reference) of any HTML element to set the different properties of ggtooltip.js.

<a href="#" 
    data-placement="top" 
    data-title="sample tooltip text">
    link text
</a>
                                

This plugin uses the HTML5 data-api that enables to maintain the validaity of HTML code elements w.r.t W3C validation standards.

jQuery API method

The tooltip plugin generates content and markup on demand, and by default places tooltips after their trigger element. Trigger the tooltip via JavaScript:

$("a").ggtooltip(); // code to initialize with defaults
$("a").ggtooltip({ textcolor : "#000000" }); // "textcolor" parameter with value "#000000"
$("a").ggtooltip({ textcolor : "#000000", placement : "right" }); // multiple parameters
                                

API uses the default JSON based { key: value } comma-separated pairs of options to set the ggtooltip properties.

CSS

Include the ggtooltip.css inside the <head> tags as shown below:

<link href="css/ggtooltip.css" rel="stylesheet" />
                                

JavaScript

Add the ggtooltip.js at the bottom of your HTML page just above the closing </body> tag.

<script type="text/javascript" src="js/ggtooltip.js"></script>
                                

HTML

After you are done with including CSS and JavaScript files you can add the following HTML markup in your page body:

<a href="#" 
    data-placement="top" 
    data-title="sample tooltip text">
    link text
</a>
                                

Usage

When you are done with adding above HTML markup code, you can call the ggtooltip method over that tag:

$("a").ggtooltip();
                                

You can insert the above code below the included ggtooltip.js script.

Options

Options can be passed via data attributes or JavaScript. For data attributes, append the option name to data-, as in data-backcolor="".

Name type default description
animation boolean true apply a CSS fade transition to the tooltip
html boolean false Insert HTML into the tooltip. If false, jQuery's text method will be used to insert content into the DOM. Use text if you're worried about XSS attacks.
placement string | function 'top' how to position the tooltip - top | bottom | left | right | auto.
When "auto" is specified, it will dynamically reorient the tooltip. For example, if placement is "auto left", the tooltip will display to the left when possible, otherwise it will display right.
selector string false If a selector is provided, tooltip objects will be delegated to the specified targets.
title string | function '' default title value if title attribute isn't present
backcolor string '#000000' Color name or Hex-code for setting the background color.
textcolor string '#ffffff' Color name or Hex-code for setting the font color.
bordercolor string '#ffffff' Color name or Hex-code for setting the border color.
trigger string 'hover focus' how tooltip is triggered - click | hover | focus | manual. You may pass multiple triggers; separate them with a space.
delay number | object 0

delay showing and hiding the tooltip (ms) - does not apply to manual trigger type

If a number is supplied, delay is applied to both hide/show

Object structure is: delay: { show: 500, hide: 100 }

Data attributes for individual tooltips

Options for individual tooltips can alternatively be specified through the use of data attributes, as explained above.

Here are positions and color examples for ggtooltip.js

Positions

Example - data-placement

Colors

backcolor textcolor bordercolor preview
#0099cc preview
#6633cc preview
#990099 preview
#0066cc preview
#cc3333 preview
#009900 preview
#cc6633 preview
#ccffff #333333 #33ffff preview
#ccccff #333333 preview
#ffcccc #333333 preview
#99ccff #333333 preview
#ffcc99 #333333 #cc9999 preview