jQuery .siblings()

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

<script>
$('.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>');
</script>
<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 Reply

Your email address will not be published. Required fields are marked *