Chapter 2. Selectors—How to Get Anything You Want
She’s just the girl She’s just the girl The girl you want | ||
-- Devo, “Girl U Want” |
jQuery harnesses the power of Cascading Style Sheets (CSS) and XPath selectors to let us quickly and easily access elements or groups of elements in the Document Object Model (DOM). In this chapter, we will explore a few of these CSS and XPath selectors, as well as jQuery’s own custom selectors. We’ll also look at jQuery’s DOM traversal methods that provide even greater flexibility for getting what we want.
The Document Object Model
One of the most powerful aspects of jQuery is its ability to make DOM traversal easy. The Document Object Model is a family-tree structure of sorts. HTML, like other markup languages, uses this model to describe the relationships of things on a page. When we refer to these relationships, we use the same terminology that we use when referring to family relationships—parents, children, and so on. A simple example can help us...