JSFiddle - React, Tailwind, and code Playground
HTML
<p class="txtRed">styled text</p>
<p class="txtPink">styled text</p>
<p class="txtBlueAndBgGrey">styled text</p>
CSS
.txtRed
{
color: #F00;
}
.txtPink
{
color: #F0F;
}
.txtBlueAndBgGrey
{
background-color: #ddd;
color: #00F;
}
JavaScript
var p_elements = document.getElementsByTagName("p");
var p_elements_length = p_elements.length;
for (var i=0; i<p_elements_length; ++i)
{
var inlineStyle = "";
if (window.getComputedStyle)// modern browsers
{
inlineStyle +=
"color:" + window.getComputedStyle(p_elements[i]).color + ";" +
"background-color:" + window.getComputedStyle(p_elements[i]).backgroundColor + ";";
}
else if (p_elements[i].currentStyle)// IE
{
inlineStyle +=
"color:" + p_elements[i].currentStyle.color + ";" +
"background-color:" + p_elements[i].currentStyle.backgroundColor + ";";
}
alert("style=\"" + p_elements[i].className + "->" + inlineStyle + "\"");
}