Exploring jQuery Selectors
page 8 of 11
by Nihar Ranjan Nayak
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 44758/ 130

Child Filters

:nth-child(index/odd/even/equation)

This will match all elements that are the nth-child of their parent or that are the parent's even or odd children. While :eq(index) matches only a single element, this matches more than one: One for each parent with index. Multiple for each parent with even, odd, or equation. The specified index is one-indexed, in contrast to :eq() which starts at zero.

                   $("ul li:nth-child(2)")

:first-child

It will find all the elements that are the first child of their parent. There is a confusion between :first and :first-child. While :first matches only a single element :first-child matches all the first elements, one for each parent.

                   $("div input:first-child")

This finds the first input elements in each matched div element. Suppose there are 3 text boxes in each div. Then the first text box of each div will be selected. That means in total 3 text boxes will be selected or matched.

:last-child

It will find all the elements that are the last child of their parent. There is a confusion between :last and :last-child. While :last matches only a single element :last-child matches all the last elements, one for each parent.

                   $("div input:last-child")

This finds the last input elements in each matched div element. Suppose there are 3 text boxes in each div. Then the last text box of each div will be selected. That means in total 3 text boxes will be selected or matched.

:only-child

This finds all the elements which are only child of their parent. If their parent has more than one elements inside them then none will be matched.

                   $("div button:only-child")

Suppose there are 3 divs. First div contains no button, Second div contains only one button and the third div contains more than one button. Then the button in the second div will be matched.


View Entire Article

User Comments

Title: good   
Name: 00
Date: 2010-01-28 10:44:36 PM
Comment:
thanks
Title: Request   
Name: Pls write more article on JQuery
Date: 2009-05-12 6:46:55 AM
Comment:
Hello Nihar
Please write more articles on JQuery.
Tume lekha ame sahajare khali padhi kam akribu
How is the IDEA?
Excellent Idea...
Title: Ureka   
Name: Lulu
Date: 2009-05-11 10:26:46 AM
Comment:
Really I have been searching this type of article for last 2 months.Thank you Nihar.
Title: Excellent boss   
Name: Sumoon
Date: 2009-05-11 10:23:15 AM
Comment:
Excellent Article boos.Please post tghis type of usefull articles more

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2019 ASPAlliance.com  |  Page Processed at 2019-03-22 8:49:46 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search