jQuery: removeClass

Imagine we have some paragraphs with a few classes applied to them.

Let’s try to remove a class from them.

<!doctype html>
<html>
<head>
    <title>removeClass demo</title>
    <script src='//code.jquery.com/jquery-1.10.2.js'></script>
    <style>
        p {
            margin: 4px;
            font-size: 16px;
            font-weight: bolder;
        }
        .blue {
            color: blue;
        }
        .under {
            text-decoration: underline;
        }
        .highlight {
            background: yellow;
        }
    </style>
</head>
<body>

<p class='blue under'>Hello</p>
<p class='blue under highlight'>and</p>
<p class='blue under'>then</p>
<p class='blue under'>Goodbye</p>

<script>
    $('p:even').removeClass('blue');
</script>

</body>
</html>

Try The Code

The p:even here will select the even number of <p> elements which are line 0 and 2 since there are 4 paragraphs here.

Series Navigation<< jQuery: Common DOM manipulation methods
jQuery: Animations and Effects. >>