(^102) ❘ CHAPTER 4 MANIPULATING CONTENT AND ATTRIBUTES
FIGURE 4-7
The toggleClass() method is demonstrated by pressing the fourth and fi nal <button> element. If
the class is present, it is removed. If the class is missing, then it is added. Like the addClass() and
removeClass() methods, the toggleClass() method can accept one or more class names; a space
character separates multiple class names.
$('button#documentToggleClass').click(
function(event)
{
event.preventDefault();
$('table').toggleClass('johnLennonAlbums');
}
);
MANIPULATING HTML AND TEXT CONTENT
jQuery provides a method for just about everything. Its unique, innovative approach to JavaScript
reinvents how you program JavaScript. This reinvention is required because jQuery methods defi ne
some ground rules that can be expected to be universal among all its methods. For example, one
ground rule that becomes more obvious as you learn more about how jQuery works is how wherever
it is possible, its methods work on one or more elements. You never have to distinguish between
whether you want to work with just one or a lot of elements, because jQuery always assumes the
possibility of an array.