Entry
Can I enumerate the (inline) styles of an element?
May 20th, 2000 09:09
Martin Honnen,
Yes, it seems that both IE and NN6 allow for standard javascript
enumeration
for (var s in element.style)
of the style properties of an element. Here is a complete example
<HTML>
<HEAD>
<SCRIPT>
function enumerateStyles (id) {
var el =
document.all ? document.all[id] :
document.getElementById(id);
var r = '';
for (var s in el.style)
r += 'element.style.' + s + ': ' + el.style[s] + '\n';
if (document.all)
document.body.insertAdjacentHTML('beforeEnd',
'<PRE>' + r + '<\/PRE>');
else {
var pre = document.createElement('PRE');
pre.appendChild(document.createTextNode(r));
document.body.appendChild(pre);
}
}
</SCRIPT>
</HEAD>
<BODY ONLOAD="enumerateStyles('aSpan');">
<SPAN ID="aSpan" STYLE="color: white; background-color: orange;">
JavaScript.FAQTs.com
</SPAN>
</BODY>
</HTML>