
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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 Articles
- 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 remove every Nth element from an array JavaScript?
- How to check if an element has a certain class name with jQuery?
- How to change an element's class with 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 add an active class to the current element with JavaScript?
- How to delete/remove an element from a C# array?
- How to remove an element from a list in Python?
- How to Toggle an Element Class in JavaScript?
- Java Program to remove an element from List with ListIterator
- How to remove an element from an array in Java
- How to remove an element from DOM using jQuery?

Advertisements