⊗jsSpStyMSS 6 of 294 menu

Multiple styles setting in JavaScript

You can set several styles at once with one command. This is done using the cssText property:

elem.style.cssText = ` width: 100px; height: 100px; display: block; `;

This property is rarely used because such an assignment removes all existing styles: it does not add, but replaces them. You can accidentally delete something you need. But it can be used, for example, for new elements, when we know for sure that we will not remove the existing style.

Rewrite a code via learned property:

elem.style.width = '100px'; elem.style.height = '100px'; elem.style.margin = '10px auto'; elem.style.color = 'red';
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