jQuery siblings() with Examples

The siblings() method in jQuery is used to return all sibling elements of the selected element.


The syntax is as follows −


Above, the filter specifies a selector expression to narrow down the search for sibling elements.

Let us now see an example to implement the jQuery siblings() method 


 Live Demo

<!DOCTYPE html>
div {
.demo * {
   display: block;
   border: 2px solid yellow;
   color: blue;
   padding: 10px;
   margin: 10px;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
      $("li.test").siblings().css({"background-color": "orange","color": "white", "border": "3px dashed blue"});
<h2>Demo Heading</h2>
<div class="demo">
<ul>ul (parent)
<li>previous sibling</li>
<li>previous sibling</li>
<li>previous sibling</li>
<li class="test">li (sibling)</li>
<li>next sibling</li>
<li>next sibling</li>
<li>next sibling</li>


This will produce the following output−