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
Post a Comment