

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove a class name from an element with JavaScript?
To remove a class name from an element with JavaScript, the code is as follows −
Example
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1" /> <style> .newStyle { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; width: 100%; padding: 25px; background-color: rgb(147, 80, 255); color: white; font-size: 25px; box-sizing: border-box; text-align: center; } </style> </head> <body> <h1>Remove className with JavaScript Example</h1> <button class="btn">Remove Class</button> <h2>Click the above button to remove className from below div</h2> <div class="newStyle" id="sampleDiv"> This is a DIV element. </div> <script> document.querySelector(".btn").addEventListener("click", addClassName); function addClassName() { var element = document.getElementById("sampleDiv"); element.classList.remove("newStyle"); } </script> </body> </html>
Output
The above code will produce the following output −
On clicking the the “Remove Class” button −
- Related Questions & Answers
- How to add a class name to an element with JavaScript?
- How to toggle between adding and removing a class name from an element with JavaScript?
- How to check if an element has a certain class name with jQuery?
- How to remove every Nth element from an array JavaScript?
- How to remove an element from a Java List?
- How to remove the border from an editable element with CSS?
- How do I remove a particular element from an array in JavaScript
- How to delete/remove an element from a C# array?
- How to remove an element from a list in Python?
- How to remove an element from an array in Java
- Java Program to remove an element from List with ListIterator
- How to remove an element from DOM using jQuery?
- How to remove an element from ArrayList in Java?
- How to add an active class to the current element with JavaScript?
- Remove an element from a Queue in Java
Advertisements