style element function


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.