cssText
In this chapter you will learn:
Print out style text
<!DOCTYPE HTML><!-- j a v a 2s .c om-->
<html>
<body>
<p id="block1" style="color: white; background-color: gray">
This is a test.
</p>
<button id="pressme">Press Me</button>
<div id="placeholder"></div>
<script>
var placeholder = document.getElementById("placeholder");
var targetElem = document.getElementById("block1");
displayStyle();
document.getElementById("pressme").onclick = function() {
targetElem.style.cssText = "color:black";
displayStyle();
}
function displayStyle() {
if (placeholder.hasChildNodes()) {
placeholder.removeChild(placeholder.firstChild);
}
var newElem = document.createElement("pre");
newElem.innerHTML += targetElem.style.cssText;
placeholder.appendChild(newElem);
}
</script>
</body>
</html>
Next chapter...
What you will learn in the next chapter: