Why Use the Widget Factory?

Writing jQuery plugins is as simple as adding a method to jQuery.prototype (more commonly seen as $.fn) and following some simple conventions like returning this for chainability. So why does the widget factory exist? And why is it hundreds of lines of code? In this document, we'll walk through the benefits of the widget factory … Continue reading

Additional jQuery Support

While we hope to cover most jQuery-related topics on this site, you may need additional or more immediate support. The following resources can prove useful. link Official Forumshttp://forum.jquery.com/ There are many subforums where you can discuss jQuery, ask questions, talk about JavaScript, or announce your plugins. Getting Started This is the best place to post … Continue reading


Traditionally webpages required reloading to update their content. For web-based email this meant that users had to manually reload their inbox to check and see if they had new mail. This had huge drawbacks: it was slow and it required user input. When the user reloaded their inbox, the server had to reconstruct the entire … Continue reading

Using jQuery UI ThemeRoller

link About ThemeRollerThemeRoller is a web app that offers a fun and intuitive interface for designing and downloading custom themes for jQuery UI. You can find ThemeRoller in the "Themes" section of the jQuery UI site, or by following this link: jQuery UI ThemeRoller link The ThemeRoller InterfaceThe interface for ThemeRoller is categorized into panels … Continue reading

Ajax and Forms

jQuery's ajax capabilities can be especially useful when dealing with forms. There are several advantages, which can range from serialization, to simple client-side validation (e.g. "Sorry, that username is taken"), to prefilters (explained below), and even more! link SerializationSerializing form inputs in jQuery is extremely easy. Two methods come supported natively: .serialize() and .serializeArray(). While … Continue reading

Inside the Event Handling Function

Every event handling function receives an event object, which contains many properties and methods. The event object is most commonly used to prevent the default action of the event via the .preventDefault() method. However, the event object contains a number of other useful properties and methods, including: link pageX, pageYThe mouse position at the time … Continue reading

CSS, Styling, & Dimensions

jQuery includes a handy way to get and set CSS properties of elements: 1 2 3 4 5 // Getting CSS properties. $( "h1" ).css( "fontSize" ); // Returns a string such as "19px". $( "h1" ).css( "font-size" ); // Also works. 1 2 3 4 5 6 7 8 9 // Setting CSS properties. … Continue reading

Widget Method Invocation

Widgets created with the widget factory use methods to change their state and perform actions after initialization. There are two ways widget methods can be invoked – through the plugin created by the widget factory, or by invoking the method on the element's instance object. link Plugin InvocationTo invoke a method using the widget's plugin, … Continue reading


At a high-level, deferreds can be thought of as a way to represent asynchronous operations which can take a long time to complete. They're the asynchronous alternative to blocking functions and the general idea is that rather than your application blocking while it awaits some request to complete before returning a result, a deferred object … Continue reading

Using jQuery UI with Bower

**Note:** This documentation refers to functionality made available in jQuery UI 1.11. Bower is a package manager for the Web. You can use Bower to download libraries like jQuery UI from the command line, without having to manually download each project from their respective sites. As an example, suppose we're starting a new project and … Continue reading

Optimize Selectors

Selector optimization is less important than it used to be, as more browsers implement document.querySelectorAll() and the burden of selection shifts from jQuery to the browser. However, there are still some tips to keep in mind when selector performance becomes a bottleneck. link jQuery ExtensionsWhen possible, avoid selectors that include jQuery extensions. These extensions cannot … Continue reading

Finding & Evaluating Plugins

One of the most celebrated aspects of jQuery is its extensive plugin ecosystem. From table sorting to form validation to autocompletion – if there's a need for it, chances are good that someone has written a plugin for it. The quality of jQuery plugins varies widely. Many plugins are extensively tested and well-maintained, but others … Continue reading

$( document ).ready()

A page can't be manipulated safely until the document is "ready." jQuery detects this state of readiness for you. Code included inside $( document ).ready() will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute. Code included inside $( window ).on( "load", function() { … }) will run … Continue reading


jQuery provides simple methods for attaching event handlers to selections. When an event occurs, the provided function is executed. Inside the function, this refers to the DOM element that initiated the event. For details on jQuery events, visit the Events documentation on api.jquery.com. The event handling function can receive an event object. This object can … Continue reading

Custom Effects with .animate()

jQuery makes it possible to animate arbitrary CSS properties via the .animate() method. The .animate() method lets you animate to a set value, or to a value relative to the current value. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 // Custom effects with .animate()$( "div.funtimes" ).animate( { … Continue reading

How do I get the text value of a selected option?

Select elements typically have two values that you want to access. First there's the value to be sent to the server, which is easy: 1 2 $( "#myselect" ).val();// => 1 The second is the text value of the select. For example, using the following select box: 1 2 3 4 5 6 7 <select … Continue reading

Append Outside of Loops

Touching the DOM comes at a cost. If you're appending a lot of elements to the DOM, you will want to append them all at once, rather than one at a time. This is a common problem when appending elements within a loop. 1 2 3 4 5 6 7 $.each( myArray, function( i, item … Continue reading

Working with JSONP

The advent of JSONP — essentially a consensual cross-site scripting hack — has opened the door to powerful mashups of content. Many prominent sites provide JSONP services, allowing you access to their content via a predefined API. A particularly great source of JSONP-formatted data is the Yahoo! Query Language, which we'll use in the following … Continue reading

Data Methods

There's often data about an element you want to store with the element. In plain JavaScript, you might do this by adding a property to the DOM element, but you'd have to deal with memory leaks in some browsers. jQuery offers a straightforward way to store data related to an element, and it manages the … Continue reading