⊗jsPmStSA 379 of 504 menu

Styling elements using the style attribute in JavaScript

Let's now learn how to add CSS styles to elements. This is done by changing the attribute style. For example, to change the color, you need to build the following chain: elem.style.color, and assign the desired color value to it.

Let's look at an example. Let's say we have this element:

<p id="elem">text</p>

Let's make this element red:

let elem = document.querySelector('#elem'); elem.style.color = 'red';

Given a div and a button. On click on the button, set a width, height, and border to the div.

English
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline