Get a specified element's style object - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Style

Description

Get a specified element's style object

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<h1 id="myH1" style="color:red">My Header</h1>

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

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

<script>
function myFunction() {// w  w w  . j  av  a2 s  .  co  m
    var x = document.getElementById("myH1").style.color;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials