O'Reilly logo

jQuery, jQuery UI, and jQuery Mobile: Recipes and Examples by Adriaan de Jonge

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

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

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