Javascript DOM CSS Style object create for an element

Introduction

You can also set the style properties of an existing element:

document.getElementById("myH1").style.color = "red";

Click the button to change the style of the H1 element.

View in separate window

<!DOCTYPE html>
<html>
<body>

<h1 id="myH1">How to change the style of a header</h1>


<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/*w ww .j  a  va2 s . co m*/
  document.getElementById("myH1").style.color = "red";
}
</script>

</body>
</html>



PreviousNext

Related