⊗jsSpStySRP 7 of 294 menu

Style reading issues in JavaScript

Only styles specified via the style attribute can be read through the style property. This means that the styles set in the CSS file cannot be read.

Let's take a look at an example. Let's say we have the following element:

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

Let the following styles be set for it in the CSS file:

#elem { color: red; }

Let's get a reference to an element into a variable:

let elem = document.querySelector('#elem');

Let's try to read the style value:

console.log(elem.style.color); // shows ''
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