Jump to content

Can't Loop Through JavaScript "style" Object...


Eyad Syria-lover

Recommended Posts

It works for me. It won't work if you run that script in the <head> section because the body has not loaded yet.

 

I would recommend using console.log() rather than document.write().

  • Like 1
Link to comment
Share on other sites

If you're trying to list all of the styles that apply to an element, then this note from the MDN page of the style property applies:

 

The style property is not useful for learning about the element's style in general, since it represents only the CSS declarations set in the element's inline style attribute, not those that come from style rules elsewhere, such as style rules in the <head> section, or external style sheets. To get the values of all CSS properties for an element you should use window.getComputedStyle() instead.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...