Skip to main content

More powerful jQuery selectors

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 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

Main Category
  • jQuery
  •  
 
Jon Moore

Search form

Jon Moore

Tips 'n' Snips

 
  • Home
  • General
  • Drupal
    • Drupal 6
    • Drupal 7
    • Module Building
  • HTML & CSS
  • Javascript
  • jQuery
  • PHP
    • CodeIgniter
    • Handy Functions
    • MySQL
  • WordPress
  • About

BBC Technology News

  • Heathrow: Man charged with flying drone near airport
  • Girl Scouts of America offer badge in cybersecurity
  • Rise in nude photos sent to phones on public transport
  • Are these the faces of the future?
  • Zimbabwe blocks Facebook, WhatsApp and Twitter amid crackdown
More

Sitepoint

  • How to Build Your First Static Site with Gatsby
  • Customer Journey Maps: A Day in the Life of a Customer
  • How to Take JavaScript Beyond the Web in 2019
  • Check out the 6 Best Productivity Apps for Designers
  • 7 Awesome Wireframing Tools You Should Be Using
More

Heart Internet

  • Did he really just say that? How to deal with an obnoxious client
  • Product management for designers
  • Talking to your clients about WordPress plugin security
  • The developer’s guide to native web animation
  • Are you seeing clearly? The role of visual thinking in creative work
More
 

Backend Coders

  • PHP
  • Handy PHP Functions
  • PHP MySQL

Frontend Coders

  • HTML & CSS
  • jQuery
  • Javascript

CMS/CMF Systems

  • Drupal
  • Drupal 6 Specific
  • Drupal 7 Specific
  • Drupal Module Building
  • WordPress

About

  • Home
  • About
 

© Jon Moore 2019

All stock images are from www.istockphoto.com