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>
    <title>not demo</title>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
        div {
            width: 50px;
            height: 50px;
            margin: 10px;
            float: left;
            background: yellow;
            border: 2px solid white;

        .green {
            background: #8f8;

        .gray {
            background: #ccc;

        #blueone {
            background: #99f;

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

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


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() >>