jQuery DOM Traversing Filter

1. Introduction

There might be the case, when we just need the first or last <li> element out of the lot. In such cases, jQuery provides us with three filtering methods –

  • first() – gets the first element out of the selected siblings
  • last() – gets the last element out of the selected siblings
  • eq() – gets the element at a specific index, the index starting at 0
  • filter() – gets all the elements matching a certain criteria
  • not() – gets all the elements NOT matching a certain criteria

2. Example Code

3. Output

jQuery Traversing Filter Output

Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.