/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// 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; }