10 examples of 'javascript add class to body' in JavaScript

Every line of 'javascript add class to body' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
14function styleBody(body) {
15 if (!body) {
16 return
17 }
18 body.classList.remove('vscode-light', 'vscode-dark', 'vscode-high-contrast');
19 body.classList.add(initData.activeTheme);
20}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

18function addClass(className) {
19 this.classList.add(className);
20
21 return this;
22}
19function addJsClass(el) {
20 var classes = document.body.className.split(" ");
21 classes.push("js");
22 document.body.className = classes.join(" ");
23}
198function addClassToDiv(div, className) {
199 const arr = div.className.split(" ");
200 if (arr.indexOf(className) === -1) {
201 div.className += ` ${className}`;
202 }
203}
118getBodyClasses() {
119 const {bodyCentered} = this.options;
120
121 let bodyClasses = this.styleSheet.body;
122 if (bodyCentered) {
123 bodyClasses = bodyClasses + this.styleSheet.centered;
124 }
125
126 return bodyClasses;
127}
19function add(el, className) {
20 if (el.classList) {
21 el.classList.add(className);
22 return;
23 }
24 var current = el.className;
25 if (!current.length) {
26 el.className = className;
27 } else if (!lookupClass(className).test(current)) {
28 el.className += ' ' + className;
29 }
30}
96addClassName(className)
97{
98 if (this._classNames.includes(className))
99 return;
100
101 this._classNames.push(className);
102
103 if (this._listItemNode)
104 this._listItemNode.classList.add(className);
105}
45function addClass(className) {
46 const firstChild = this.getFirstChild();
47
48 firstChild.addClass(className);
49}
7function addJavascript(jsname, pos) {
8
9 var th = document.getElementsByTagName(pos)[0];
10 var s = document.createElement('script');
11 s.setAttribute('type', 'text/javascript');
12 s.setAttribute('src', jsname);
13 th.appendChild(s);
14
15};
46private toggleBodyClass(isAdd: boolean): void {
47 if (isAdd) {
48 this.renderer.addClass(this.documentRef.body, ModalComponent.MODEL_OPEN_CSS);
49 return;
50 }
51
52 this.renderer.removeClass(this.documentRef.body, ModalComponent.MODEL_OPEN_CSS);
53}

Related snippets