jquery Selector Usage notes (part I.)

Source: Internet
Author: User

Because I use jquery more in my project, and I feel that jquery is really good, especially with its flexible and efficient selectors it is even more unforgettable. So, write a very basic article about the jquery selector today, and a passing friend can collect it for reference.

1, $ ("*")--Select all elements

* Selector selects each individual element in the document, including HTML, head, and body.

If used with other elements (nested selectors, as in the example above), the selector selects all child elements in the specified element.

If you select all the elements within the body we can do this: $ (body *)

2, $ ("#id")--Select the element that corresponds to the ID

# Select an element with a unique specified ID.

ID refers to the id attribute of the HTML element.

The same ID value can only be used once in the document.

To select an element with an ID of content: $ ("#content")

Note: IDs do not start with numbers, some browsers may have problems

3, $ (". Class")--selects all elements of the specified class

. Selector selects the element with the specified class.

Class refers to the class attribute of the HTML element.

Unlike the ID selector, the class selector is often used for multiple elements.

This allows you to set a specific style for any HTML element with the same class.

Note: Class names do not start with numbers, and some browsers may have problems

To select all elements of the class title: $ (". Title")

4, $ (Element)--Select the element that specifies the label name

The element selector selects elements with the specified label name.

The label name refers to the text between < and > of the HTML tag.

To select all P elements: $ (P)

5, $ ("P:first")--Select the first P element

: The first selector selects the second element.

Most common usage: use with other elements to select the first element in a specified group

6, $ ("P:last")--Select the last P element

: Last selector selects the final element.

Most common usage: use with other elements to select the last element in the specified group

7, $ ("Tr:even")--Select all even <tr> elements

: The even selector selects each element with an even index value (such as 2, 4, 6).

The index value starts at 0, and all the first elements are even (0).

Most common usage: use with other elements/selectors to select elements of even numbers in the specified group

8, $ ("tr:odd")--Select all odd <tr> elements

: The odd selector selects each element with an odd index value (such as 1, 3, 5).

The index value starts at 0, and all the first elements are even (0).

Most common usage: use with other elements/selectors to select odd ordinal elements in a specified group

Today, let's introduce some of these, and then continue to talk about other selector usage, please look forward to

jquery Selector Usage notes (part I.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.