jQuery: siblings

The siblings method allows us to search through the siblings of these elements in the DOM tree and construct a new jQuery object from the matching elements.

<!doctype html>
<html>
<head>
    <title>eq demo</title>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
    <style>
        li {
            background: yellow;
        }

        .silver {
            background: silver;
        }
    </style>
</head>
<body>

<ul>
    <li>list item 1</li>
    <li>list item 2</li>
    <li class='third-item'>list item 3</li>
    <li>list item 4</li>
    <li>list item 5</li>
</ul>

<script>
    $('li.third-item').siblings().addClass('silver');
</script>

</body>
</html>

YOUR TEXT

Notice that list items 1, 2, 4 and 5 are selected but not list item 3.

Series Navigation<< jQuery: .filter()
jQuery: not >>