add class to body javascript code example
Example 1: add class to body javascript
var body = document.body;
body.classList.add("body_class");
Example 2: javascript add class to element
var someElement= document.getElementById("myElement");
someElement.className += " newclass";
Example 3: javascript add div to body with class
var MainDiv = document.createElement('div');
var ChildDiv1 = MainDiv.createElement('div');
ChildDiv1.className = 'contextmenu_contextMenu_3_a2Z contextmenu_ContextMenuFocusContainer_2thYU';
ChildDiv1.tabIndex = "0";
ChildDiv1.style = "visibility: visible; bottom: 56px; right: 68px;"
var ChildDiv2 = ChildDiv1.createElement('div');
ChildDiv1.className = 'contextmenu_contextMenuContents_1yyTu';
var DivButton1 = ChildDiv2.createElement('div');
DivButton1.className = 'contextmenu_contextMenuItem_CBC-y contextMenuItem';
DivButton1.value = "Upload an Image";
var DivButton2 = ChildDiv2.createElement('div');
DivButton2.className = 'contextmenu_contextMenuItem_CBC-y contextMenuItem';
DivButton2.value = "Share Your Trade Offer URL";
document.body.appendChild(MainDiv);