THE WORLD'S LARGEST WEB DEVELOPER SITE
×

HOW TO

HowTo Home

Menus

Icon Bar Menu Icon Accordion Tabs Vertical Tabs Tab Headers Top Navigation Responsive Topnav Side Navigation Fullscreen Navigation Off-Canvas Menu Hover Sidenav Buttons Horizontal Scroll Menu Vertical Menu Fixed Menu Slide Down Bar on Scroll Sticky Navbar Hover Dropdowns Click Dropdowns Pagination Breadcrumbs Button Group Vertical Button Group

Images

Slideshow Modal Images Lightbox Responsive Image Grid Image Grid Image Overlay Image Effects Image Text Full Page Image Hero Image Rounded Images Meet the Team Flip an Image Shake an Image Portfolio Gallery Portfolio with Filtering

Buttons

Alert Buttons Animated Buttons Social Media Buttons Loading Buttons Next/prev Buttons Round Buttons Scroll To Top Button

Forms

Login Form Signup Form Contact Form Clear Input Field Animated Search Password Validation

Filters

Filter List Filter Table Filter Elements Sort List Sort Table

More

Modal Boxes Timeline Progress Bars Skill Bar Range Sliders Tooltips Popups Calendar Responsive Tables HTML Includes To Do List Loaders Star Rating Overlay Effect Contact Chips Cards Profile Card Alerts Notes Fixed Footer Equal Height Clearfix Snackbar Toggle Switch Scroll Drawing Pricing Table Parallax Aspect Ratio Build a Web Site Toggle Like/Dislike Toggle Hide/Show Toggle Class Add Class Remove Class Arrows Animate Icons Countdown Timer Typewriter Coming Soon Page Center Website Thumbnails Testimonials Draggable HTML Element Syntax Highlighter JS Animations

Grid

2 Column Layout 3 Column Layout 4 Column Layout Mixed Column Layout

Google

Google Maps Google Translate Google Charts Google Fonts

Converters

Convert Weight Convert Temperature Convert Length Convert Speed

How TO - Remove a Class


Learn how to remove a class name from an element with JavaScript.


Click the button to remove a class from me!

Remove Class

Step 1) Add HTML:

In this example, we will use a button to remove the "mystyle" class from the <div> element with id="myDIV":

Example

<button onclick="myFunction()">Try it</button>

<div id="myDIV" class="mystyle">
  This is a DIV element.
</div>


Step 2) Add CSS:

Style the specified class name:

Example

.mystyle {
    width: 100%;
    padding: 25px;
    background-color: coral;
    color: white;
    font-size: 25px;
}

Step 3) Add JavaScript:

Get the <div> element with id="myDIV" and remove the "mystyle" class from it:

Example

function myFunction() {
    var element = document.getElementById("myDIV");
    element.classList.remove("mystyle");
}
Try it Yourself »

Cross-browser solution

Note: The classList property is not supported in Internet Explorer 9. The following code will work in all browsers:

Example

function myFunction() {
    var element = document.getElementById("myDIV");
    element.className = element.className.replace(/\bmystyle\b/g, "");
}
Try it Yourself »

Tip: Also see How To Toggle A Class.

Tip: Also see How To Add A Class.

Tip: Learn more about the classList property in our JavaScript Reference.

Tip: Learn more about the className property in our JavaScript Reference.