Javascript DOM HTML CSSStyleDeclaration cssText Property set

Introduction

Set the text of the element's inline style declaration:

document.getElementById("ex1").style.cssText = "color: blue;";

Click the button to set the value of the inline style of the H1 element.

The value of the inline style is completely overwritten.

View in separate window

<!DOCTYPE html>
<html>
<body>
<h1 style="color:red; font-size: 50px">The cssText Property</h1>
<button onclick="myFunction()">Test</button>


<script>
function myFunction() {/*from ww  w.  j a  v a2s .  c o  m*/
  var elmnt = document.getElementsByTagName("h1")[0];
  elmnt.style.cssText = "color: blue;";
}
</script>

</body>
</html>



PreviousNext

Related