Use Stylesheets for Changing CSS on Many Elements

If you’re changing the CSS of more than 20 elements using .css(), consider adding a style tag to the page instead for a nearly 60% increase in speed. 1 2 3 4 5 6 // Fine for up to 20 elements, slow after that:$( “a.swedberg” ).css( “color”, “#0769ad” ); // Much faster:$( “<style type=\”text/css\”>a.swedberg { … Continue reading

Don’t Act on Absent Elements

jQuery won’t tell you if you’re trying to run a whole lot of code on an empty selection – it will proceed as though nothing’s wrong. It’s up to you to verify that your selection contains some elements. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 … 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

How To Use the Widget Factory

While most existing jQuery plugins are stateless – that is, we call them on an element and that is the extent of our interaction with the plugin – there’s a large set of functionality that doesn’t fit into the basic plugin pattern. In order to fill this gap, jQuery UI has implemented a more advanced … 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

Using jQuery UI with AMD

**Note:** This documentation refers to functionality made available in jQuery UI 1.11. As of jQuery UI 1.11, all of the library’s source files support using AMD. This means that you can manage your jQuery UI dependencies without using Download Builder, and load jQuery UI’s source files asynchronously using an AMD loader such as RequireJS. In … Continue reading

Using the classes Option

As of the 1.12 release, the jQuery UI widget factory includes a means of managing CSS class names through the classes option. This article will give you an overview of how the classes option works, and discuss what you can do with it. link Syntax overviewThe classes option is used to map structural class names … Continue reading

Extending Widgets with the Widget Factory

jQuery UI’s widget factory makes it easy to build widgets that extend the functionality of existing widgets. Doing so allows you to build powerful widgets on top of an existing base, as well as make small tweaks to an existing widget’s functionality. Note: This article assumes some basic knowledge of what the widget factory is … Continue reading

Cache Length During Loops

In a for loop, don’t access the length property of an array every time; cache it beforehand. 1 2 3 4 5 6 7 var myLength = myArray.length; for ( var i = 0; i < myLength; i++ ) { // do stuff }