Home arrow JavaScript arrow Page 4 - 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 - Displaying the markup contained in web page links
(Page 4 of 4 )

By means of the "bodyHandler" parameter, it is possible to perform all sorts of clever tasks with tooltips, since as you saw before, it accepts a callback function as an entrant parameter. Based on this functionality, below I coded a final example. It shows how to build tooltips that have the ability to display their own text. Take a look at the following code sample to find out how this is accomplished:

 

<!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, using bodyHandler option

$(document).ready(function(){

$("a").tooltip({

delay: 0,

track: true,

bodyHandler: function() {

return $(this).html();

}

});

});

</script>

</head>

<body>

<div>

<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>

</div>

</body>

</html>

Short to code and read, isn't it? As you can see, now the callback function attached to the "bodyHandler" argument is capable of displaying the text included in each web page link. Of course, this is merely a simple demonstration of what can actually be done with this argument, so I strongly encourage you to develop your own examples and define more complex functions to be attached to this argument. It'll be an instructive experience, believe me.

Final thoughts

In this fifth installment of the series, I discussed the use of the "bodyHandler" argument, which can be really useful for injecting HTML code into tooltips, in this way completely altering its default visual appearance and behavior.

Nonetheless, as I explained before, the examples developed so far weren't suitable for use in production environments. But that is about to change. In the next part of the series I'm going to show you how to use this parameter for displaying full-size versions of a group of thumbnail images.

Want to see how this will be done? Then don't miss the upcoming article!  


DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

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 11 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials