How do I select an item using class or ID?

This code selects an element with an ID of "myDivId". Since IDs are unique, this expression always selects either zero or one elements depending upon whether or not an element with the specified ID exists. 1 $( "#myDivId" ); This code selects an element with a class of "myCssClass". Since any number of elements can … Continue reading

Using jQuery UI

In addition to being available on CDNs and Download Builder, jQuery UI also integrates into a number of development environments.

jQuery Mobile

jQuery Mobile is the easiest way to build sites and apps that are accessible on all popular smartphone, tablet, and desktop devices. This framework provides a set of touch-friendly UI widgets and an AJAX-powered navigation system to support animated page transitions.

Keep Things DRY

Don't repeat yourself; if you're repeating yourself, you're doing it wrong. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 // BADif ( eventfade.data( "currently" ) !== "showing" ) { eventfade.stop();} if ( eventhover.data( "currently" ) !== "showing" ) { eventhover.stop();} if ( … Continue reading

How do I test whether an element exists?

Use the .length property of the jQuery collection returned by your selector: 1 2 3 4 5 if ( $( "#myDiv" ).length ) { $( "#myDiv" ).show(); } Note that it isn't always necessary to test whether an element exists. The following code will show the element if it exists, and do nothing (with no … Continue reading

Code Organization

Understanding the basic mechanics is one thing, but the essence of building applications is understanding how to organize code so that it is navigable and well-encapsulated instead of a whole slew of global functions.