Element style Property - Add a red color to an <h1> element: - Javascript DOM

Javascript examples for DOM:Element style

Description

Element style Property - Add a red color to an <h1> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP" style="border-top: 5px solid red;">Click the button to get the value of my top border.</p>

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

<p id="demo"></p>

<script>
function myFunction() {/*from   w w w.j  a  va  2  s . c  om*/
    var x = document.getElementById("myP").style.borderTop;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials