Book Image

jQuery Plugin Development Beginner's Guide

By : Giulio Bai
Book Image

jQuery Plugin Development Beginner's Guide

By: Giulio Bai

Overview of this book

<p>jQuery is the most famous JavaScript library. If you use jQuery a lot, it can be a good idea to start packaging your code into plugins. A jQuery plugin is simply a way to put your code into a package, which makes it easier to maintain your code and use across different projects. While basic scripting is relatively straightforward, writing plugins can leave people scratching their heads.<br /><br />With this exhaustive guide in hand, you can start building your own plugins in a matter of minutes! This book takes you beyond the basics of jQuery and enables you to take full advantage of jQuery's powerful plugin architecture to deliver highly interactive content to your website viewers.<br /><br />This book contains all the information you need to successfully author your very own jQuery plugin with a particular focus on the practical aspect of design and development. <br /><br />This book will also cover some details of real life plugins and explain their functioning to gain a better understanding of the overall concept of plugin development and jQuery plugin architecture.<br /><br />Different topics regarding plugin development are discussed, and you will learn how to develop many types of add-ons, ranging from media plugins (such as slideshows, video and audio controls, and so on) to various utilities (image pre-loading, handling cookies) and use and applications of jQuery effects and animations (sliding, fading, combined animations) to eventually demonstrate how all of these plugins can be merged and give birth to a new, more complex, and multipurpose script that comes in handy in a lot of situations.</p>
Table of Contents (20 chapters)
jQuery 1.4 Plugin Development
Credits
About the Author
About the Reviewers
Preface

Custom jQuery selectors


Suppose we have a page with some text written in, which also contains a few links to both internal pages (that is, pages on the same server) and external websites.

We are presented with different choices in terms of which elements to apply the tooltip to (referring to links as an example, but they apply to any kind of element as well), as follows:

  • All the links

  • All the links with a specific class (for example, tooltip)

  • All the links with the title attribute not empty

  • All the links pointing to internal pages

  • All the links pointing to external websites

  • Combinations of the above

We can easily combine the first three conditions with the others (and with themselves) using CSS selectors appropriately. For example:

  • $("a"), all the links

  • $("a.tooltip"), links having a tooltip class

  • $("a[title]"), links with a title attribute (still have to check if empty)

  • $("a.tooltip[title]"), links with a tooltip class and a title attribute

As for internal and external pages, we have to work with...