… whereas in jQuery, this can be shortened to:
This may not seem so impressive at first, but the $() function above can also select any element in the page, including all elements using a certain class (which for most current browsers, would require far, far more scripting):
Anyway, if you have a UCL web account on the Apache server, you can easily try these out for yourself. For instance, we’d recommend the ‘Getting started with jQuery‘ tutorial to get an idea of some of the other immense capabilities of jQuery.
A solution for this has been suggested by Google, and we’d recommend users to try implementing it. When loading a framework into your page, rather than store the scripts on your own site, refer them to Google. If a user goes to a site that uses this Google stored script, their browser will hopefully cache the script. If the user then goes to another site that refers to the Google stored script, they won’t have to download it again, because the script will already be cached in the browser. This will obviously cut out unnecessary duplication, and generally make things faster for browsers.
To load the Google stored libraries, include the following code in your page header:
The ‘google.load()’ function contains two arguments. The first is for the framework, the second for the version. For full details, see Google’s AJAX Libraries API documentation.