Styling via JavaScript

From Zanecorpwiki

Jump to: navigation, search

When manipulating styling in JavaScript, there's a wrinkle. Most browsers work fine with "element.style = 'color: yellow'", but not IE (and not just because of IE's problems with attributes).

The 'recommended method is to access the style object like:

element.style.color = 'yellow';

Be aware that there there is a change in naming convention. We go from from the CSS '-' naming scheme to stead capping. E.g., 'background-color' becomes 'backgroundColor'.

Other IE problems: some perfectly valid style rules cause errors and your script to die. For instance:

element.style.display = 'table-row'

is an error on IE! I shit you not.

Personal tools