More powerful jQuery selectors

:first The first match of the page. li a:first returns the first link also under a list item :last The last match of the page. li a:last returns the last...

:first The first match of the page. li a:first returns the first link also under a list item

:last The last match of the page. li a:last returns the last link also under a list item

:first-child The first child element. li:first-child returns the first item of each list

:last-child The last child element. li:last-child returns the last item of each list

:only-child Returns all elements that have no siblings.

:nth-child(n) The nth child element. li:nth-child(2) returns the 2nd list item of each list. (Note: the counting starts at 1 not 0 as per usual programming practice).

:nth-child(even|odd) Even or odd children. li:nth-child(even) returns the even children of each list.

:even and :odd Even and odd matching elements page-wide. li:even returns every even list item.

Info from jQuery in Action by Bibeault Katz

Related posts:

  1. Powerful jQuery Tag Selectors
  2. jQuery Photo Reflections
  3. Adding jQuery to your page
  4. To ‘Get’ an element in jQuery

This post has had 15 views