instance method Element#adjacent

View source on GitHub →

Element#adjacent(selector...) → [Element…]
  • selector (String) – A CSS selector.

Finds all siblings of the current element that match the given selector(s). If you provide multiple selectors, siblings matching any of the selectors are included. If a sibling matches multiple selectors, it is only included once. The order of the returned array is not defined.


Assuming this list:

<ul id="cities">
  <li class="us" id="nyc">New York</li>
  <li class="uk" id="lon">London</li>
  <li class="us" id="chi">Chicago</li>
  <li class="jp" id="tok">Tokyo</li>
  <li class="us" id="la">Los Angeles</li>
  <li class="us" id="aus">Austin</li>


// -> [li#chi, li#la, li#aus]
$('nyc').adjacent('', '');
// -> [li#lon, li#tok]

This method can be called either as an instance method or as a generic method. If calling as a generic, pass the instance in as the first argument.