You can act on your selection results immediately, within the same line of code. jQuery allows you to simply call a method of the returned selection (or another jQuery method) directly from the selection. Alternatively, you can store the results in a variable for use later in your code (as the preceding examples have shown).
This example finds the selection and then acts on it immediately, as a group, using the jQuery addClass
method to add a CSS class to each item in the selection.
$('a').addClass('alink'),
You can also store your selection for later use. When you do so, jQuery stores a reference (not a copy) to the elements in the selection. You can then use the returned jQuery object to call other jQuery methods, as in the following:
var sel = $('a'),
sel.addClass('alink'),
The examples in the following sections will use both approaches to acting on your jQuery selections.