jQuery has :nth-child() Selector that can be used khổng lồ select all nth-childs of their parent & apply the style to lớn those elements.
Bạn đang xem: How to use jquery children and find jquery child
We can pass similar parameters as we pass in CSS. Such as the index of the child element child (starting with 1) or the string odd/even, or even an equation for eg. :nth-child(even), :nth-child(2n).
jQuery strictly implements :nth- selectors directly from the CSS specification, so the value of n is “1-indexed”, which means that the counting of child elements starts at 1.
Other jQuery methods like .first() or .eq() follows “0-indexed” counting that is derived from JavaScript.
Xem thêm: Bí Quyết Trị Nám Da Dân Gian Tại Nhà Được Nhiều Người Lựa Chọn
This is how we can select the first element:
...$( "li:nth-child(1)");...With :nth-child(n), all children are counted và the specified element is selected only if it matches the selector attached khổng lồ the pseudo-class.
Examples:
Find the second li in each matched ul và change the color.
Credit: jQuery Docs
child css selectors elements examples nth-child style chia sẻ this post
Apr 8 JSON.stringify() in JavaScript Apr 7 Middleware in NextJS Jan 17 4 advanced ways to search Colleague Jan 16 Colleague UI Basics: The search Area Jan 16 Colleague UI Basics: The Context Area
#1 How to check if radio button is checked or not using JavaScript? #2 How to địa chỉ cửa hàng Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 Solution to the error “Visual Studio Code can’t be opened because táo khuyết cannot kiểm tra it for malicious software” #5 How lớn uninstall Cocoapods from the Mac OS?
Most Read
#1 How to check if radio button is checked or not using JavaScript? #2 How to địa chỉ cửa hàng Read More Read Less Button using JavaScript? #3 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #4 Solution to the error “Visual Studio Code can’t be opened because hãng apple cannot check it for malicious software” #5 How khổng lồ uninstall Cocoapods from the Mac OS? #6 PHP Login System using PDO Part 1: Create User Registration PageRecently Posted
#Apr 8 JSON.stringify() in JavaScript #Apr 7 Middleware in NextJS #Jan 17 4 advanced ways to search Colleague #Jan 16 Colleague UI Basics: The search Area #Jan 16 Colleague UI Basics: The Context Area #Jan 16 Colleague UI Basics: Accessing the user interfaceThe Difference Between the echo và print Commands in PHPPHPThe substr() method in JavaScript và how it’s different from substring()JavaScriptHow to showroom a scroll back to đứng đầu button using JavaScript và CSS?CSS5 Ways to lớn Loop Through JavaScript ArraysJavaScriptHow to lớn create a Random Hex color generator using JavaScript?JavaScriptALTER DATABASE in PostgreSQLPostgresHow khổng lồ Find the Highest (or Lowest) Number in an Array in JavaScript?JavaScriptHow to Sort (Shuffle) an Array in Random Order in JavaScript?JavaScriptHow khổng lồ create a pricing table using flex in CSS?CSSSorting Arrays in JavaScriptJavaScriptHow to lớn detect the Blog Page in WordPress?WordPressHow khổng lồ Draw a Circle in HTML5 Using Canvas Tag?HTML Designed và Developed By Yogesh Chauhan About Me RSS Feed Privacy