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.

Detach Elements to Work with Them

The DOM is slow; you want to avoid manipulating it as much as possible. jQuery introduced detach() in version 1.4 to help address this issue, allowing you to remove an element from the DOM while you work with it. 1 2 3 4 5 6 7 8 var table = $( "#myTable" );var parent = … Continue reading

How do I select elements when I already have a DOM element?

If you have a variable containing a DOM element, and want to select elements related to that DOM element, simply wrap it in a jQuery object. 1 2 3 var myDomElement = document.getElementById( "foo" ); // A plain DOM element. $( myDomElement ).find( "a" ); // Finds all anchors inside the DOM element. Many people … Continue reading

How do I disable/enable a form element?

You can enable or disable a form element using the .prop() method: 1 2 3 4 5 // Disable #x$( "#x" ).prop( "disabled", true ); // Enable #x$( "#x" ).prop( "disabled", false );

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.