\n\n\n\nA: You can try this\nvar element = document.getElementById('element_id');\nelement.style.backgroundColor = \"color or color_code\";\n\nExample.\nvar element = document.getElementById('firstname');\nelement.style.backgroundColor = \"green\";//Or #ff55ff\n\nJSFIDDLE\n\nA: KISS Answer:\ndocument.getElementById('element').style.background = '#DD00DD';\n\n\nA: You can do it with JQuery: \n$(\".class\").css(\"background\",\"yellow\");\n\n\nA: You might find your code is more maintainable if you keep all your styles, etc. in CSS and just set / unset class names in JavaScript.\nYour CSS would obviously be something like:\n.highlight {\n background:#ff00aa;\n}\n\nThen in JavaScript:\nelement.className = element.className === 'highlight' ? '' : 'highlight';\n\n\nA: You can use:\n\n\n\nA: $(\"body\").css(\"background\",\"green\"); //jQuery\n\ndocument.body.style.backgroundColor = \"green\"; //javascript\n\nso many ways are there I think it is very easy and simple\nDemo On Plunker\n\nA: $('#ID / .Class').css('background-color', '#FF6600');\n\nBy using jquery we can target the element's class or Id to apply css background or any other stylings\n\nA: var element = document.getElementById('element');\nelement.style.background = '#FF00AA';\n\n\nA: Or, using a little jQuery:\n$('#fieldID').css('background-color', '#FF6600');\n\n\nA: In general, CSS properties are converted to JavaScript by making them camelCase without any dashes. So background-color becomes backgroundColor.\nfunction setColor(element, color)\n{\n element.style.backgroundColor = color;\n}\n\n// where el is the concerned element\nvar el = document.getElementById('elementId');\nsetColor(el, 'green');\n\n\nA: you can use \n$('#elementID').css('background-color', '#C0C0C0');\n\n\nA: Changing CSS of a HTMLElement\nYou can change most of the CSS properties with JavaScript, use this statement:\ndocument.querySelector().style[] = \n\nwhere , , are all String objects.\nUsually, the style property will have the same name as the actual name used in CSS. But whenever there is more that one word, it will be camel case: for example background-color is changed with backgroundColor.\nThe following statement will set the background of #container to the color red:\ndocumentquerySelector('#container').style.background = 'red'\n\nHere's a quick demo changing the color of the box every 0.5s:\n\n\ncolors = ['rosybrown', 'cornflowerblue', 'pink', 'lightblue', 'lemonchiffon', 'lightgrey', 'lightcoral', 'blueviolet', 'firebrick', 'fuchsia', 'lightgreen', 'red', 'purple', 'cyan']\r\n\r\nlet i = 0\r\nsetInterval(() => {\r\n const random = Math.floor(Math.random()*colors.length)\r\n document.querySelector('.box').style.background = colors[random];\r\n}, 500)\n.box {\r\n width: 100px;\r\n height: 100px;\r\n}\n\n\n\n\nChanging CSS of multiple HTMLElement\nImagine you would like to apply CSS styles to more than one element, for example, make the background color of all elements with the class name box lightgreen. Then you can:\n\n\n*\n\n*select the elements with .querySelectorAll and unwrap them in an object Array with the destructuring syntax:\nconst elements = [...document.querySelectorAll('.box')]\n\n\n*loop over the array with .forEach and apply the change to each element:\nelements.forEach(element => element.style.background = 'lightgreen')\n\nHere is the demo:\n\n\nconst elements = [...document.querySelectorAll('.box')]\r\nelements.forEach(element => element.style.background = 'lightgreen')\n.box {\r\n height: 100px;\r\n width: 100px;\r\n display: inline-block;\r\n margin: 10px;\r\n}\n\r\n\r\n\r\n\n\n\n\nAnother method\nIf you want to change multiple style properties of an element more than once you may consider using another method: link this element to another class instead.\nAssuming you can prepare the styles beforehand in CSS you can toggle classes by accessing the classList of the element and calling the toggle function:\n\n\ndocument.querySelector('.box').classList.toggle('orange')\n.box {\r\n width: 100px;\r\n height: 100px;\r\n}\r\n\r\n.orange {\r\n background: orange;\r\n}\n\n\n\n\nList of CSS properties in JavaScript\nHere is the complete list:\nalignContent\nalignItems\nalignSelf\nanimation\nanimationDelay\nanimationDirection\nanimationDuration\nanimationFillMode\nanimationIterationCount\nanimationName\nanimationTimingFunction\nanimationPlayState\nbackground\nbackgroundAttachment\nbackgroundColor\nbackgroundImage\nbackgroundPosition\nbackgroundRepeat\nbackgroundClip\nbackgroundOrigin\nbackgroundSize\nbackfaceVisibility\nborderBottom\nborderBottomColor\nborderBottomLeftRadius\nborderBottomRightRadius\nborderBottomStyle\nborderBottomWidth\nborderCollapse\nborderColor\nborderImage\nborderImageOutset\nborderImageRepeat\nborderImageSlice\nborderImageSource \nborderImageWidth\nborderLeft\nborderLeftColor\nborderLeftStyle\nborderLeftWidth\nborderRadius\nborderRight\nborderRightColor\nborderRightStyle\nborderRightWidth\nborderSpacing\nborderStyle\nborderTop\nborderTopColor\nborderTopLeftRadius\nborderTopRightRadius\nborderTopStyle\nborderTopWidth\nborderWidth\nbottom\nboxShadow\nboxSizing\ncaptionSide\nclear\nclip\ncolor\ncolumnCount\ncolumnFill\ncolumnGap\ncolumnRule\ncolumnRuleColor\ncolumnRuleStyle\ncolumnRuleWidth\ncolumns\ncolumnSpan\ncolumnWidth\ncounterIncrement\ncounterReset\ncursor\ndirection\ndisplay\nemptyCells\nfilter\nflex\nflexBasis\nflexDirection\nflexFlow\nflexGrow\nflexShrink\nflexWrap\ncontent\nfontStretch\nhangingPunctuation\nheight\nhyphens\nicon\nimageOrientation\nnavDown\nnavIndex\nnavLeft\nnavRight\nnavUp>\ncssFloat\nfont\nfontFamily\nfontSize\nfontStyle\nfontVariant\nfontWeight\nfontSizeAdjust\njustifyContent\nleft\nletterSpacing\nlineHeight\nlistStyle\nlistStyleImage\nlistStylePosition\nlistStyleType\nmargin\nmarginBottom\nmarginLeft\nmarginRight\nmarginTop\nmaxHeight\nmaxWidth\nminHeight\nminWidth\nopacity\norder\norphans\noutline\noutlineColor\noutlineOffset\noutlineStyle\noutlineWidth\noverflow\noverflowX\noverflowY\npadding\npaddingBottom\npaddingLeft\npaddingRight\npaddingTop\npageBreakAfter\npageBreakBefore\npageBreakInside\nperspective\nperspectiveOrigin\nposition\nquotes\nresize\nright\ntableLayout\ntabSize\ntextAlign\ntextAlignLast\ntextDecoration\ntextDecorationColor\ntextDecorationLine\ntextDecorationStyle\ntextIndent\ntextOverflow\ntextShadow\ntextTransform\ntextJustify\ntop\ntransform\ntransformOrigin\ntransformStyle\ntransition\ntransitionProperty\ntransitionDuration\ntransitionTimingFunction\ntransitionDelay\nunicodeBidi\nuserSelect\nverticalAlign\nvisibility\nvoiceBalance\nvoiceDuration\nvoicePitch\nvoicePitchRange\nvoiceRate\nvoiceStress\nvoiceVolume\nwhiteSpace\nwidth\nwordBreak\nwordSpacing\nwordWrap\nwidows\nwritingMode\nzIndex\n\n\nA: Javascript:\ndocument.getElementById(\"ID\").style.background = \"colorName\"; //JS ID\n\ndocument.getElementsByClassName(\"ClassName\")[0].style.background = \"colorName\"; //JS Class\n\nJquery:\n$('#ID/.className').css(\"background\",\"colorName\") // One style\n\n$('#ID/.className').css({\"background\":\"colorName\",\"color\":\"colorname\"}); //Multiple style\n\n\nA: A simple js can solve this:\ndocument.getElementById(\"idName\").style.background = \"blue\";\n\n\nA: $(\".class\")[0].style.background = \"blue\";\n\n"},"meta":{"kind":"string","value":"{\n \"language\": \"en\",\n \"url\": \"https://stackoverflow.com/questions/3319\",\n \"timestamp\": \"2023-03-29T00:00:00\",\n \"source\": \"stackexchange\",\n \"question_score\": \"129\"\n}"}}},{"rowIdx":343,"cells":{"text":{"kind":"string","value":"Q: Capturing TAB key in text box I would like to be able to use the Tab key within a text box to tab over four spaces. The way it is now, the Tab key jumps my cursor to the next input.\nIs there some JavaScript that will capture the Tab key in the text box before it bubbles up to the UI?\nI understand some browsers (i.e. FireFox) may not allow this. How about a custom key-combo like Shift+Tab, or Ctrl+Q?\n\nA: I would advise against changing the default behaviour of a key. I do as much as possible without touching a mouse, so if you make my tab key not move to the next field on a form I will be very aggravated.\nA shortcut key could be useful however, especially with large code blocks and nesting. Shift-TAB is a bad option because that normally takes me to the previous field on a form. Maybe a new button on the WMD editor to insert a code-TAB, with a shortcut key, would be possible?\n\nA: In Chrome on the Mac, alt-tab inserts a tab character into a