Answers for "replace class in javascript on click"

12

javascript change element class

//Overwrite all classes
element.className = "class";

//Add class
element.classList.add("class");
Posted by: Guest on June-02-2020
3

change class javascript

Syntax:
document.getElementById('myElement').className = "myclass";

<html> 
    <head> 
        <title>Change class of an element with javascript</title> 
        <style type="text/css"> 
            .redbutton{ 
                background-color: red; 
            } 
            .greenbutton{ 
                background-color: green; 
            } 
        </style> 
        <script type="text/javascript"> 
            function changeClass() { 
                document.getElementById('cli
Posted by: Guest on April-21-2020

Code answers related to "replace class in javascript on click"

Code answers related to "Javascript"

Browse Popular Code Answers by Language