7 examples of 'javascript change background color' in JavaScript

Every line of 'javascript change background color' 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
55function changeBackgroundColor(color) {
56 var script = 'document.body.style.backgroundColor="' + color + '";';
57 // See https://developer.chrome.com/extensions/tabs#method-executeScript.
58 // chrome.tabs.executeScript allows us to programmatically inject JavaScript
59 // into a page. Since we omit the optional first argument "tabId", the script
60 // is inserted into the active tab of the current window, which serves as the
61 // default.
62 chrome.tabs.executeScript({
63 code: script
64 });
65}
33function highlightColor(color) {
34 document.getElementById('black').style.border = "2px solid black";
35 document.getElementById('red').style.border = "2px solid black";
36 document.getElementById('yellow').style.border = "2px solid black";
37 document.getElementById('green').style.border = "2px solid black";
38 document.getElementById('blue').style.border = "2px solid black";
39
40 document.getElementById(color).style.border = "3px solid orange";
41 var vColor;
42 switch( color ) {
43 case "red":
44 vColor = [255, 0, 0];
45 break;
46 case "yellow":
47 vColor = [255, 255, 0];
48 break;
49 case "green":
50 vColor = [0, 255, 0];
51 break;
52 case "blue":
53 vColor = [0, 0, 255];
54 break;
55 default:
56 vColor = [0, 0, 0];
57 break;
58 }
59 vwf_view.kernel.setProperty( appID, "lineColor", vColor );
60}
38function changeBackgroundColor () {
39 const maxIdx = COLORS.length - 1
40 const idx = Math.floor(Math.random() * Math.floor(maxIdx))
41 const newColor = COLORS[idx]
42
43 document.body.style.background = newColor
44}
39(function changeColor () {
40 var r = Math.floor(Math.random() * 156) + 100,
41 g = Math.floor(Math.random() * 156) + 100,
42 b = Math.floor(Math.random() * 156) + 100;
43 $pre.css("color", "rgb(" + r + ", " + g + ", " + b + ")");
44 window.setTimeout(changeColor, 50);
45})();
193function selectColor(value) {
194 buttonCtrl.hidePanel();
195 buttonCtrl.color(value);
196 applyFormat(buttonCtrl.settings.format, value);
197}
207function setBorderColor(layer, hexColour) {
208 if (hexColour == colorToFind) {
209 var fill = layer.style().borders().firstObject();
210
211 if (fill != undefined) {
212 replaceCount++;
213 fill.color = MSColor.colorWithRed_green_blue_alpha(colorToReplace.r / 255, colorToReplace.g / 255, colorToReplace.b / 255, 1.0);
214 }
215 }
216}
68function SetActiveColor( color )
69{
70 if ( color && color.length > 0 )
71 document.getElementById('eActive').style.color = color ;
72 else
73 document.getElementById('eActive').style.color = window.document.alinkColor ;
74}

Related snippets