Các selectors cơ bản cho phép các nhà phát triển để lựa chọn các yếu tố của loại thẻ, tên lớp, ID, hoặc sự kết hợp bất kỳ của chúng. Trong khi xem http://localhost/testing/, khởi động hộp thoại Firebug, và nhấp vào tab Console (xem Hình 1-4). Nếu bảng điều khiển bị tắt, hãy nhấp vào tab Console, và chọn Enabled. Bạn sẽ sử dụng giao diện này cho tất cả các ví dụ trong chương này. | CHAPTER 1 INTRODUCING JQUERY Basic Selectors The basic selectors allow developers to select elements by tag type class name ID or any combination thereof. While viewing http testing launch the Firebug dialog and click the Console tab see Figure 1-4 . If the Console panel is disabled click the Console tab and select Enabled. You will be using this console for all examples in this chapter. Note If you re familiar with CSS you will be able to skim this section because the selectors behave the same as their CSS counterparts. Selecting Elements by Tag Type To select an element by tag type simply use the name of the tag such as p div or span as your selector element To select all paragraph p tags in our test document enter the following snippet at the bottom of the console p Press Enter and the code will execute. The following results will be displayed in the console see Figure 1-4 p p p p bar The first line shows the command that was executed and the second line shows what was returned from the code. There are four paragraph tags in our test document two without class or ID attributes one with a class foo and one with an ID bar you ll learn about this syntax in the next sections . When we pass the tag name to the jQuery function all instances are found and added to the jQuery object. 11 CHAPTER 1 INTRODUCING JQUERY 900 Testing jQuery - 0 J i _ j . http local host testing wOT l i. Coogie T esti ng jQuc ry Hello World Another paragraph but this one has a class. This is a span inside a paragraph. Paragraph with an id. And this sentence is in a span. A Console HTML CSS Script DOM Net Jiffy Page Speed Page Speed Activity Q e 0 Goff Clear Profile loaded Con text11 p p p bar 8 Done e zi Figure 1 -4. The Firebug console after executing a command Selecting Tags by Class Name Just as quickly as you can select by tag type you can select elements by their assigned class or classes. The syntax for this is the use the class name preceded by a period . .