.siblings()

In this chapter you will learn:

  1. Syntax and Description

Syntax and Description

.siblings([selector])

gets the siblings of each element in the set of matched elements, optionally filtered by a selector. selector (optional) is a string containing a selector expression to match elements against. Its return value is the new jQuery object.

Consider a page with a simple list as follows:

<ul>/*  j ava2 s  .  c o  m*/
 <li>list item 1</li>
 <li>list item 2</li>
 <li class="third-item">list item 3</li>
 <li>list item 4</li>
 <li>list item 5</li>
</ul>

$('li.third-item').siblings().css('background-color', 'red'); marks items 1, 2, 4, and 5.

As we do not supply a selector expression, all of the siblings are part of the object. If we had supplied one, only the matching items among these four would be included.

Next chapter...

What you will learn in the next chapter:

  1. Description for .scrollLeft()(getter)
  2. Get the scroll bar horizontal position
  3. Syntax for .scrollLeft(value) (setter)