Set the style properties of an existing element: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Style

Description

Set the style properties of an existing element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<h1 id="myH1">a header</h1>

<button onclick="myFunction()">change the style of the H1 element</button>

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

</body>
</html>

Related Tutorials