How Can I Use RemoveClass Method In JQuery With Example

admin_img Posted By Bajarangi soft , Posted On 14-10-2020

In Jquery removeClass() - Removes one or more classes from the selected elements. So today we discuss how to use removeclass in jquery

How Can I Use RemoveClass Method In JQuery With Example

Step 1:Create index.html file and implement below code.

<h1 class="blue">Heading 1</h1>
<h2 class="blue">Heading 2</h2>

<p class="blue">This is a paragraph.</p>
<p>This is another paragraph.</p>

<button class="btn btn-primary">Remove classes to elements</button>


Step 2:Implement jquery to use RemoveClass method.

<script>
    $(document).ready(function(){
        $("button").click(function(){
            $("h1, h2, p").removeClass("blue");
        });
    });
</script>


Complete Code For RemoveClass Method In JQuery

<!DOCTYPE html>
<html>
<head>
    <title>How Can I Use RemoveClass Method In JQuery With Example</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
</head>
<style>
    body {
        background: darkolivegreen;
    }

    .important {
        font-weight: bold;
        font-size: xx-large;
    }

    .blue {
        color: blue;
    }
</style>
<body>
<div class="container">
    <br><br><br>
    <div class="text-center">
        <h2 id="color" style="color: White">RemoveClass Method In JQuery </h2>
    </div>
    <br>
    <br>

    <div class="well">
        <h1 class="blue">Heading 1</h1>
        <h2 class="blue">Heading 2</h2>

        <p class="blue">This is a paragraph.</p>
        <p>This is another paragraph.</p>

        <button class="btn btn-primary">Remove classes to elements</button>

    </div>

</div>
</body>
</html>
<script>
    $(document).ready(function(){
        $("button").click(function(){
            $("h1, h2, p").removeClass("blue");
        });
    });
</script>

Related Post