jQuery child element filter
Note:
1. :nth-child(index) starts from 1, and eq(index) starts from 0, that is to say $(" ul li:nth-child(0)").css("color","red") cannot obtain matching elements and can only start from 1, that is $("ul li:nth-child(1) ").css("color","red"), and eq(0) can be obtained, the same is to obtain the first child element
:nth-child(even) is to obtain the even number of child elements, That is, the second, fourth, sixth..., and :even starts from index 0, matching the second index, the fourth index..., that is, the first, the third, The fifth..., it seems that they all get an odd number of items, the same is true for :nth-child (odd) and :odd
2. :first-child matches the child elements of each parent class , and :first matches a child element, and the same goes for :last-child and last
3. only-child: matches an element that is the only child element in the parent element, that is, the current child element is The only element in the class matches!
无标题页
- Course Recommendations
- Courseware download
-
IntermediateFront-end Vue3 actual combat [handwritten vue project]
2857 people are watching -
ElementaryAPIPOST tutorial [Popularization of technical concepts related to network communication]
1795 people are watching -
IntermediateIssue 22_Comprehensive actual combat
5521 people are watching -
ElementaryIssue 22_PHP Programming
5172 people are watching -
ElementaryIssue 22_Front-end development
8713 people are watching -
IntermediateBig data (MySQL) video tutorial full version
4525 people are watching -
ElementaryGo language tutorial-full of practical information and no nonsense
2794 people are watching -
ElementaryGO Language Core Programming Course
2814 people are watching -
IntermediateJS advanced and BootStrap learning
2563 people are watching -
IntermediateSQL optimization and troubleshooting (MySQL version)
3374 people are watching -
IntermediateRedis+MySQL database interview tutorial
2963 people are watching -
ElementaryDeliver food or learn programming?
5708 people are watching
Students who have watched this course are also learning
- Let's briefly talk about starting a business in PHP
- Quick introduction to web front-end development
- Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
- Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
- Login verification and classic message board
- Computer network knowledge collection
- Quick Start Node.JS Full Version
- The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
- Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
- About us Disclaimer Sitemap
- php.cn:Public welfare online PHP training,Help PHP learners grow quickly!
Name | Description | Example |
:nth -child(index/even/odd/equation) | Matches the Nth child or odd-even element under its parent element ':eq(index)' only matches one element, And this one will match child elements for every parent element. :nth-child starts from 1, and :eq() starts from 0! Can be used: |
Find the second li in each ul: $("ul li: nth-child(2)") |
:first-child | matches the first child element ':first' only Matches an element, and this selector will match a child element for each parent element |
Find the first li in each ul: $("ul li:first-child ") |
:last-child | matches the last child element ':last'matches only one element, and this selection The symbol will match a child element for each parent element |
Find the last li in each ul: $("ul li:last- child") |
If an element is the only child element of the parent element, it will be matchedIf the parent element contains other elements, it will not be matched. | Find the li that is the only child element in ul:
$("ul li:only-child") |