5 examples of 'set style in javascript' in JavaScript

Every line of 'set style in javascript' 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
24set(style, value) {
25 if (hasStyles[style]) {
26 this[style] = value;
27 } else {
28 if (this._items[style] !== value) {
29 this._items[style] = value;
30 this._node.onSetStyle(style, value);
31 }
32 }
33}
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

172function setStyle(value) {
173 if (value !== stylePicker.value()) {
174 stylePicker.setValue(value);
175 }
176
177 alignmentPane.setStyle(value);
178 fontEffectsPane.setStyle(value);
179 originalAlignmentPaneValue = alignmentPane.value();
180 originalFontEffectsPaneValue = fontEffectsPane.value();
181
182 // If it is a default (nameless) style or is used, make it undeletable.
183 if (value === "" || editorSession.isStyleUsed(editorSession.getParagraphStyleElement(value))) {
184 deleteButton.domNode.style.display = 'none';
185 } else {
186 deleteButton.domNode.style.display = 'block';
187 }
188}
71function setStyleValue(
72 style: CSSStyleDeclaration, prop: string, value: string) {
73 if (prop.indexOf('-') >= 0) {
74 style.setProperty(prop, value);
75 } else {
76 // TODO(tomnguyen) Figure out why this is necessary.
77 // tslint:disable-next-line:no-any
78 (style as any)[prop] = value;
79 }
80}
7function setStyles(domElement, styles) {
8 Object.keys(styles).forEach(name => {
9 const rawValue = styles[name];
10 const isEmpty = rawValue === null || typeof rawValue === 'boolean' || rawValue === '';
11
12 // Unset the style to its default values using an empty string
13 if (isEmpty) domElement.style[name] = '';
14 else {
15 const value =
16 typeof rawValue === 'number' && !isUnitlessProperty(name) ? `${rawValue}px` : rawValue;
17
18 domElement.style[name] = value;
19 }
20 });
21}
77function injectStyle(css) {
78 head = head || document.head || document.getElementsByTagName('head')[0];
79 var style = document.createElement('style');
80 style.type = 'text/css';
81 /* istanbul ignore if */
82
83 if (style.styleSheet) {
84 style.styleSheet.cssText = css; // for IE8 and below
85 } else {
86 style.appendChild(document.createTextNode(css));
87 }
88
89 prepend(head, style);
90}

Related snippets