Posted By

antij on 05/21/10


Tagged

css style


Versions (?)

style element function


 / Published in: JavaScript
 

  1. // pass styles object like {background:'red', color:'white'}
  2. function styleElement(elem, styles) {
  3. for (var prop in styles) {
  4. try {
  5. if (elem.style[prop] != undefined) elem.style[prop] = styles[prop];
  6. } catch (e) {
  7. if (elem.currentStyle) {
  8. if (elem.currentStyle[prop] != undefined) elem.currentStyle[prop] = styles[prop];
  9. }
  10. }
  11. }
  12. return elem;
  13. }

Report this snippet  

You need to login to post a comment.