The siblings method in jQuery
Using the method siblings you can find all the neighbors of an element. Let's look at the HTML code:
<p>text</p>
<p>text</p>
<p id="test">text</p>
<p>text</p>
<p>text</p>
Then we apply the method siblings:
$('#test').siblings().html('!');
By passing a selector to the method, you can perform additional filtering of neighbors, for example like this:
$(#test).siblings('.zzz').html('!');
Find all neighbors of li with class www.
Find all neighbors of li with class www that (neighbors) have class test.
Find all neighbors of li with class www, but NOT a neighbor with class test.