Chapter 2. Creating the wrapped element set
This chapter covers
- Selecting elements to be wrapped by jQuery using selectors
- Creating and placing new HTML elements in the DOM
- Manipulating the wrapped element set
In the previous chapter, we discussed the many ways that the jQuery $() function can be used. Its capabilities range from the selection of DOM elements to defining functions to be executed when the DOM is loaded.
In this chapter, we examine in great detail how the DOM elements to be operated upon are identified by looking at two of the most powerful and frequently used capabilities of $(): the selection of DOM elements via selectors and the creation of new DOM elements.
A good number of the capabilities required by Rich Internet Applications are achieved by manipulating the DOM elements that make up the pages. But before they can be manipulated, they need to be identified and selected. Let’s begin our detailed tour of the many ways that jQuery lets us specify what elements are to be targeted for manipulation.
The first thing we need to do when using virtually any jQuery method (frequently referred to as jQuery commands) is to select some page elements to operate upon. Sometimes, the set of elements we want to select will be easy to describe, such as “all paragraph elements on the page.” Other times, they’ll require a more complex description like “all list elements that have the class listElement and contain a link.”