jQuery: not

This entry is part 31 of 33 in the series jQuery Tutorial

For not method, the supplied selector is tested against each element; the elements that don’t match the selector will be included in the result.

<!doctype html>
<html>
<head>
    <title>not demo</title>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
    <style>
        div {
            width: 50px;
            height: 50px;
            margin: 10px;
            float: left;
            background: yellow;
            border: 2px solid white;
        }

        .green {
            background: #8f8;
        }

        .gray {
            background: #ccc;
        }

        #blueone {
            background: #99f;
        }
    </style>
</head>
<body>

<div></div>
<div id='blueone'></div>
<div></div>
<div class='green'></div>
<div class='green'></div>
<div class='gray'></div>
<div></div>

<script>
    $('div').not('.green, #blueone')
            .css('border-color', 'red');
</script>

</body>
</html>

Post Your Gameplays

In this example, class=’green’ and id=’blueone’ will be excluded when applying the .css method.

Series Navigation<< jQuery: siblings
jQuery: .each() >>