Javascript DOM CSS Style color Property get

Introduction

Return the text-color of a <p> element:

alert(document.getElementById("myP").style.color);

View in separate window

<!DOCTYPE html>
<html>
<body>

<p id="myP" style="color:red;">This is an example paragraph.</p>

<button type="button" onclick="myFunction()">Return text color of p</button>

<p id="demo"></p>
<script>
function myFunction() {//from  w w w. ja v  a 2s. co  m
  document.getElementById("demo").innerHTML = document.getElementById("myP").style.color;
}
</script>

</body>
</html>



PreviousNext

Related