Return to Snippet

Revision: 27084
at May 21, 2010 11:03 by antij


Initial Code
// pass styles object like {background:'red', color:'white'}
function styleElement(elem, styles) {
  for (var prop in styles) {
    try {
      if (elem.style[prop] != undefined) elem.style[prop] = styles[prop];
    } catch (e) {
      if (elem.currentStyle) {
        if (elem.currentStyle[prop] != undefined) elem.currentStyle[prop] = styles[prop];
      }
    }
  }
  return elem;
}

Initial URL

                                

Initial Description

                                

Initial Title
style element function

Initial Tags
css, style

Initial Language
JavaScript