O'Reilly logo

Microsoft Visual Studio 2015 Unleashed, Third Edition by Mike Snell, Lars Powers

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Acting on Your Selection

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required