Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

change elements class javascript

document.getElementById("MyElement").classList.add('MyClass');

document.getElementById("MyElement").classList.remove('MyClass');

if ( document.getElementById("MyElement").classList.contains('MyClass') )
{
document.getElementById("MyElement").classList.toggle('MyClass');
}
Comment

javascript change element class

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

//Add class
element.classList.add("class");
Comment

javascript change class name

function switchMode(){
    
    // Body switching
    if(document.getElementById("page-body").className == "page-body-day"){
        document.getElementById("page-body").className = "page-body-night";
    }else{
        document.getElementById("page-body").className = "page-body-day";
    }

    // Heading switching
    if(document.getElementById("main-heading").className == "main-heading-day"){
        document.getElementById("main-heading").className = "main-heading-night";
    }else{
        document.getElementById("main-heading").className = "main-heading-day";
    }

}
Comment

change class js

let containsClass = element.classList.contains('my-class');
element.classList.toggle('my-class', !containsClass);
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript clear text in textarea 
Javascript :: javascript group array by key 
Javascript :: search partial string in array javascript 
Javascript :: string iterate in js 
Javascript :: getting user input in node js 
Javascript :: javascript check if undefined or null 
Javascript :: onclick go to url 
Javascript :: reactjs checkbox 
Javascript :: How to change favicon in nextjs. 
Javascript :: checkbox click event jquery 
Javascript :: Use Recursion to Create a Countdown 
Javascript :: sqlite3 multithreading nodejs 
Javascript :: jquery loop through json 
Javascript :: slice until character javascript 
Javascript :: refresh page on back button click javascript 
Javascript :: angular get current time 
Javascript :: react font awesome npm 
Javascript :: como remover uma variável de um json 
Javascript :: setting proxy in npm 
Javascript :: MIN_SAFE_INTEGER 
Javascript :: node cron every second 
Javascript :: ctx linecap 
Javascript :: two button in one row react native 
Javascript :: fibonacci series in javascript 
Javascript :: local storage check max size 
Javascript :: javascript assign value to input using name 
Javascript :: ng build JS stacktrace 
Javascript :: increase-memory-limit not working node 
Javascript :: object foreach 
Javascript :: jqeury cdn 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =