jquery siblings() method


  Translation results:

siblings

UK ['sɪblɪŋz] US ['sɪblɪŋz]

n.Brothers, sisters (plural noun of sibling)

jquery siblings() methodsyntax

Function: siblings() Gets the siblings of each element in the matching set. Filtering through the selector is optional.

Syntax: .siblings(selector)

Parameters:

Parameter Description
selector String value, containing the selector expression used to match elements.

Description: If given a jQuery object that represents a collection of DOM elements, the .siblings() method allows us to search for these elements in the DOM tree. Sibling elements and constructs a new jQuery object with the matching element. This method accepts an optional selector expression of the same type as the argument we passed into the $() function. If this selector is applied, elements will be filtered by testing whether they match the selector.

jquery siblings() methodexample

<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>
</head>

<body>
  <div><span>Hello</span></div>
  <p class="selected">Hello Again</p>
  <p>And Again</p>

<script>
$("p").siblings(".selected").css("background", "yellow");
</script>

</body>
</html>
Run instance »

Click the "Run instance" button to view the online instance

Home

Videos

Q&A