Join Joe Marini for an in-depth discussion in this video Overview of selectors and filters, part of jQuery Essential Training.
- View Offline
- As I talked about earlier, retrieving content from a page is a very basic and common web development pattern. This is where jQuery selectors and filters come in handy. It's one of the main things that jQuery makes a lot easier to accomplish with a lot less code, and that's what we're going to look at in this chapter. Selectors and filters work together to retrieve document content. Selectors are used to select content, as their name implies, and then filters are used to further refine the selected content. In this way, you can think of selectors and filters as the query part of jQuery.
Of course, you can get access to the underlying DOM element for each one of these objects if you want to. But the whole purpose of using jQuery objects is that you have a whole bunch of convenience functions and high level ways of operating on them without having to resort to the DOM. Let's consider a conceptual example. Suppose I have a web application that presents a gallery of photos. I might want to do some processing of all the photo elements in the page. For example, add event handlers or sort them, or perform some other operation.
Selectors make this easy by allowing me to specify a simple expression that returns all the images in the page, which I can then manipulate. Of course, the best way to learn about how selectors and filters work is to actually see them in action. In the rest of this chapter, we'll see how selectors and filters work together to retrieve content based on different kinds of criteria.
- What is jQuery?
- Using selectors and filters to extract information
- Creating, inserting, and animating page content
- Handling events
- Understanding jQuery statement chaining
- Working with CSS
- Building event handlers
- Animating with jQuery: showing, hiding, and fading page elements
- Working with AJAX