This page is somewhere for me to note down the most important jQuery concepts while I'm learning it. For a proper reference, see the official API reference.
The example HTML page below shows how to load jQuery and install a simple handler:
This simple example waits until the DOM is ready and then installs a click handler on all
<a> tags on the page to pop up an alert box when clicked. The
read() handler is widely used, as it doesn't make sense to manipulate the DOM until it's fully instantiated.
This example can be decomposed into its elements:
| || This adds a handler to be called when the DOM is fully loaded. It takes a callback function as its parameter, in this case (and frequently) an anonymous function defined in-place. Note that
| || This is a jQuery selector, returning a jQuery object representing all
| || Installs a click handler on the specified set of elements, similar to the
There are two ways to select attributes in jQuery, both of which can be combined:
#itemto select tags with a specified
.titleto select tags with the specified CSS class. Many selectors can take another selector as a “parameter” and modify it. See the full list for more details.
jQueryobject act as selectors, returning a restricted set of elements.
not()method, which filters the set of items returned to be those not matching the specified selector.