jQuery .siblings()

jQuery .siblings() gets the siblings of each element in the set of matched elements, optionally filtered by a selector;

js:


$('.target').siblings().css('background', '#ffa').append(' <span class="label label-info">siblings for .target</span>');

$('.target').siblings('.selected').append(' <span class="label">siblings with class .selected</span>');

html:


<ul>

    <li class="selected">list item .selected</li>

    <li>list item</li>

    <li class="target">list item <strong>.target</strong></li>

    <li class="selected">list item .selected</li>

    <li>list item</li>

</ul>​

Leave a Comment