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