[jquery selector: Nth-child] Select to match the nth child or odd-even element under its parent element

Source: Internet
Author: User

Select the nth child or odd-even element that matches the parent element:

Instance:

<! DOCTYPE html>;} Html{font:15px/1.2em ' Courier New '; color: #666;} div > *{margin:10px 0; cursor:pointer;}    #demo {width:750px;margin:75px Auto;} button{padding:5px 15px;border:0;outline:none;margin-top:-5px;border-radius:2px;font:400 12px/1.2em ' Courier New ';} . active{background-color:yellow;transition:. 3s;} . Hover{background-color:red;transition:. 3s} p{text-indent:8px;}</style><script type= ' Text/javascript ' >/** matches the nth sub-or odd-even element under its parent element: EQ (index) matches only one element, and this will match child elements for each parent element: Nth-child starts with 1, and: eq () is          from 0. Available:: Nth-child (even): Nth-child (odd): Nth-child (3n): Nth-chi LD (2): Nth-child (3n+1): Nth-child (3n+2) accepts parameter even odd represents odd even, and also receives expression algorithm*/    $(function(){        $(' P:nth-child (1) '). Toggleclass (' active '); });</script>inchdiv.</p> <div style= ' border:1px solid #3695BC ' > <p>the First paragraphinchDiv.</p> <p>the last ParagraphinchThe div.</p> </div> <div style= ' border:1px solid #3695BC ' > <p>the first P AragraphinchAnother div.</p> <p>the last paragraphinchAnother div.</p> </div> </div></body>

[jquery selector: Nth-child] Select to match the nth child or odd-even element under its parent element

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.