All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

jQuery Remove All Classes

Last Updated : Mar 11, 2024

jQuery Remove All Classes

In this article we will show you the solution of jQuery remove all classes, here we are going to show you example for remove class from element with the help of removeClass() method. The removeClass() method removes one or more class names from the selected elements.

If removeClass() method had no parameter then it will removes all class from particular selected elements. So we can remove all classes from paragraph <p> tag elements in html.

Step By Step Guide On jQuery Remove All Classes :-

Here we defined heading tag, three paragraph tags with three different class attribute values ‘one,two,three’ and at last button ‘Click’.

In script block we defined ready() method which is automatically starts loading code of within this function when this program opened on browser and within that defined click() method with element name ‘button’ so which is refers when clicks on button click() event will load particular process.

There we defined removeClass() method with no class name as parameter with p tag it will removes all classes from all p tags.

<!DOCTYPE html>
<html>
    <head>
        <title>REMOVE ELEMENT USING JQUERY</title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
        <script>
            $(document).ready(function(){
                $("button").click(function(){
                    $("p").removeClass();
                });
            });
        </script>
    </head>
    <body>
        <style>
            .one{
                color: blue;
            }
            .two{
                color: green;
            }
            .three{
                color: yellow;
            }
        </style>
        <h1 class="intro">Welcome All</h1>
        <p class="one">This is first paragraph tag</p>
        <p class="two">This is second paragraph tag</p>
        <p class="three"> This is third paragraph tag</p>
        <button>Click</button>
    </body>
</html>
  1. <!DOCTYPE html> tag which is instruct the web browser about what version of HTML file written in and it’s not have any ending tag.
  2. The<html> tag is used to indicate the beginning of HTML document.
  3. As above shown <head> tag is contain information about webpage and external file links are declared here. <title> tag is used for set the webpage title.
  4. Here we imported open source jquery library support file which is needed for coding using jquery in program.
  5. Both <head> and <title> tags having their pair end tag, so we need to close the ending tags respectively. If you’re not closed anyone of ending tag properly that is also affect the webpage result.
  6. <body> tag is beginning of main coding part because it contain coding of entire website blocks and elements described here.
  7. In script we defined ready() and click() method within that we are goings to removing all classes ‘one,two,three’ from all ‘p’ para elements in html code by using ‘removeClass()’ method without parameter.
  8. So which process will begin when user clicks on button after loading this program on browser and in style block we defined three properties ‘font color as blue, green, yellow’ for respective classes ‘one,two,three’.
  9. In html block we defined h1 tag with text ‘Welcome All’ and two para tags with respective contents ‘This is first paragraph tag, This is second paragraph tag, This is third paragraph tag’, each one have different class attributes ‘one,two,three’ and lastly button ‘Click’.
  10. Both </body>,</html> tags closed respectively. </body> tag indicates the end of body, Then </html> tag indicates the end of HTML document.

Conclusion :-

In conclusion now we are able to know how to remove all classes from any element in jquery.

Before execution of program we needs to confirm internet connection because then only that jquery file will supports defined jquery codes without error.

When we executes program on browser we can see heading, three lines of text each line texts has different style so its looks in different colors and a button, user needs to clicks on button then all line texts color gone because we removed all classes style from common p element.

I hope this article on jQuery remove all classes helps you and the steps and method mentioned above are easy to follow and implement.

Author Image About Dikshita

Passionate Electronics and Communication Engineering student with expertise in web development (HTML, CSS, JS,PHP, Bootstrap, React.js) and content writing. Eager problem solver and tech enthusiast, adept at creating engaging web experiences.

Follow Dikshita On Linkedin 🡪