JQuery subattribute filter selector Usage Analysis-jquery-js tutorial

Source: Internet
Author: User
This article mainly introduces the usage of the jQuery subattribute filter selector. Examples include: first-child, last-child, nth-child, and ,: only-chilid and other sub-attribute filtering selector usage tips. For more information about jQuery sub-attribute filtering selector usage, see the following example. Share it with you for your reference. The specific analysis is as follows:

1.: first-child Selector

Select all elements of the first child element of the parent level. format:

The Code is as follows:

$ ("Selector: first-child ")

For example:

The Code is as follows:

$ ("Ul: first-child" ).css ("text-decoration", "underline" ).css ("color", "blue ");

2.: last-child Selector

Used to select all the elements of the last child element of the parent level. format:

The Code is as follows:

$ ("Selector: last-child ")

For example:

The Code is as follows:

$ ("Ul: last-child" ).css ("text-decoration", "underline" ).css ("color", "red ");

3.: nth-child Selector

Select the nth child or parity element under the parent element.

Syntax format:

The Code is as follows:

$ ("Selector: nth-child (index/even/odd/equation )");

For example:

The Code is as follows:

$ ("Ul li: nth-child (4)" ).css ("color", "red "); // set the text color of the 5th elements under the ul element to red, that is, the index value of the li element is 4.

4.: only-chilid Selector

The unique Selector Used to select an element.

Format:

The Code is as follows:

$ ("Selector: only-chilid ")

Simple Example:

The Code is as follows:





Child element filter Selector

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.