1

Let's say I have this simple style:

   .element {
     width: 60px;
   }

But I have no DOM element with that class. Can I use pure JS to get that style? getComputedStyle() presupposes you are accessing a something the DOM has computed. If so, could someone explain which CSSOM element would be used to access it?

serraosays
  • 7,163
  • 3
  • 35
  • 60

1 Answers1

2

Yes, we can access the styles if they are just included in html and may not be computed to any DOM element.

document.styleSheets provides array of styles sheets attached and we can parse those using loop.

Example: I have attached the example from this same page.

Please see this image for better understanding