propattrstyle
by xiaoji121
HTML
<div id="d1">d1</div>
<div id="d2">d2</div>
CSS
* { font-family:Arial; }
div { width:400px; height:100px; background:#eee; font-size:12px; margin-bottom:1px; }
JavaScript
function getStyle(obj) {
obj.innerHTML = '.style.cssText=' + (obj.style.cssText).toLowerCase() +
'<br>.getAttribute("style")=' + ("" + obj.getAttribute("style")).toLowerCase();
}
(function () {
var d1 = document.getElementById("d1");
var d2 = document.getElementById("d2");
var styleText = "background-color:rgb(51, 204, 204); font-size:16px";
d1.style.cssText = styleText;
d2.setAttribute("style", styleText);
getStyle(d1);
getStyle(d2);
}());