Home arrow JavaScript arrow Page 2 - Using the jQuery Tooltip Plug-in`s bodyHandler Argument
JAVASCRIPT

Using the jQuery Tooltip Plug-in`s bodyHandler Argument


In this fifth installment of a seven-part series on the jQuery Tooltip plug-in, I discuss the use of the “bodyHandler” argument. It can be really useful for injecting HTML code into tooltips, thus altering their default visual appearance and behavior.

Author Info:
By: Alejandro Gervasio
Rating: 5 stars5 stars5 stars5 stars5 stars / 3
November 02, 2009
TABLE OF CONTENTS:
  1. · Using the jQuery Tooltip Plug-in`s bodyHandler Argument
  2. · Review: the top and left parameters
  3. · Adding HTML markup to tooltips with the bodyHandler input argument
  4. · Displaying the markup contained in web page links

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
Using the jQuery Tooltip Plug-in`s bodyHandler Argument - Review: the top and left parameters
(Page 2 of 4 )

Since in the introduction I mentioned that the Tooltip plug-in had the ability to control the coordinates at which tooltips were shown on the browser via the "top" and "left" arguments, it'd be helpful to spend a minute or two reviewing the code samples that demonstrated this process. With that idea in mind, below I listed these examples, so you can quickly recall quickly how they looked. Here they are:

(example on using the top and left parameters to alter default positions of tooltips)

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Tooltip example using the top and left arguments</title>

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

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

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

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

<script type="text/javascript">

// assign tooltip to links after web page has been loaded

// delay tooltip display 400 ms, track mouse position, fade it and assign left-top coordinates

$(document).ready(function(){

$("a").tooltip({

delay: 400,

track: true,

fade: 250,

top: -25,

left: 40

});

});

</script>

</head>

<body>

<ul>

<li><a href="http://jquery.com" title="Sample Link 1">Sample Link 1</a></li>

<li><a href="http://jquery.com" title="Sample Link 2">Sample Link 2</a></li>

<li><a href="http://jquery.com" title="Sample Link 3">Sample Link 3</a></li>

<li><a href="http://jquery.com" title="Sample Link 4">Sample Link 4</a></li>

<li><a href="http://jquery.com" title="Sample Link 5">Sample Link 5</a></li>

<li><a href="http://jquery.com" title="Sample Link 6">Sample Link 6</a></li>

</ul>

</body>

</html>

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

<title>Tooltip Example</title>

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

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

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

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

<script type="text/javascript">

// assign tooltip to links after web page has been loaded

// delay tooltip display 400 ms, do not track mouse position, fade it and assign left-top coordinates

$(document).ready(function(){

$("a").tooltip({

delay: 400,

fade: 500,

top: -10,

left: 40

});

});

</script>

</head>

<body>

<ul>

<li><a href="http://jquery.com" title="Sample Link 1">Sample Link 1</a></li>

<li><a href="http://jquery.com" title="Sample Link 2">Sample Link 2</a></li>

<li><a href="http://jquery.com" title="Sample Link 3">Sample Link 3</a></li>

<li><a href="http://jquery.com" title="Sample Link 4">Sample Link 4</a></li>

<li><a href="http://jquery.com" title="Sample Link 5">Sample Link 5</a></li>

<li><a href="http://jquery.com" title="Sample Link 6">Sample Link 6</a></li>

</ul>

</body>

</html>

As shown above, modifying the default coordinates used by the plug-in for displaying them on screen is reduced to assigning the proper values in pixels to the respective "top" and "left" arguments and nothing else. In the first case, the tooltips not only will be shown at a different position, but they will follow any mouse movements, while in the second example, the mouse tracking feature has been disabled; the "track" argument has been removed.

At this point, you're hopefully pretty familiar with playing with the "top" and "left" parameters, right? So I'm going to show how to use yet another argument given by the Tooltip plug-in, called "bodyHandler." It will come in handy for adding HTML code within the tooltips.

To see how this new argument will be used in a concrete example, click on the link below and read the following section.


blog comments powered by Disqus
JAVASCRIPT ARTICLES

- More Top jQuery Tutorials for Beginners
- More Top jQuery Plugins for Menus
- Top jQuery Tutorials for Beginners
- New UI Framework and SDK for JavaScript Rele...
- JavaScript OpenPGP Tool, Node.js 0.6.3 Avail...
- Yahoo Releases Cocktails Language and Develo...
- Customizing jQuery Slideshows: Dynamic Contr...
- Customizing jQuery Slideshows: the animate()...
- Customizing jQuery Slideshows: slideUp() and...
- Customizing jQuery Slideshows: hide() and sh...
- Web Workers: Performing Calculations in Para...
- More Top JavaScript Frameworks and Libraries
- More Dynamic jQuery Styling Techniques
- The Top JavaScript Libraries
- The Top JavaScript Frameworks

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials