Chapter 3. Modifying the Page

This chapter covers jQuery’s methods for manipulating the HTML tree. This includes classes, attributes, properties, and elements. This chapter also shows the difference between methods with similar names and discusses potential performance issues.

Recipe: Adding Classes

Without jQuery, browsers restrict you to setting all classes in a single call. You cannot add or remove classes without taking into account other classes on the element. This adds extra complexity and overhead when you want to want to add another class to an element. Fortunately, jQuery offers the addClass() function, which overcomes this hurdle by providing the ability to easily add one or more classes to a selector.

Listing 3.1 shows how you can ...

Get jQuery, jQuery UI, and jQuery Mobile: Recipes and Examples now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.