It is one of the common tasks that a developer performs on a
web page - adding and removing classes. For adding a class, we have to use
addClass() function.
Listing 9
$("a").addClass("tableStyle");
It has been assumed that tableStyle is a predefined class.
Similarly for removing a class, we can use removeClass () function.
Chainability
jQuery allows us to concatenate together operations into a
single expression. Every method within jQuery returns the query object itself,
allowing the programmer to "chain" upon it. In other words, most of
the jQuery wrapper methods returns a reference to the jQuery object itself so
that we can go on adding operations to a single expression when we need to
perform multiple manipulations on the wrapped object. Let us take the example
of the statements below.
Listing 10
$('#someId').addclass('someClass');
$('#someId').show();
The operation performed by the above two statements can be
performed in one statement as shown below.
Listing 11
$('#someId').addclass('someClass').show();
Like the above examples, there are a lot of functionalities
which can be performed using jQuery using the minimal code.