Create Element With Class Name Javascript Code Example


Example 1: create element javascript with class


// create div element by javascript with class

var div = document.createElement('div');
div.className = "div1";

Example 2: element.classname javascript


let el = document.getElementById('item');

if (el.className === 'active'){
el.className = 'inactive';
} else {
el.className = 'active';
}

Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable