Javascript DOM CSS Style backgroundColor Property get for <div>

Introduction

Return the background color of a specific <div> element:

View in separate window

<!DOCTYPE html>
<html>
<body>

<h1>Hello World!</h1>

<div id="myDiv" style="background-color:orange;">This is a div element.</div>
<br>
<button type="button" onclick="myFunction()">Get the background color of div</button>
<p id="demo"></p>
<script>
function myFunction() {/*from www .  j  ava2s  . c  om*/
  document.getElementById("demo").innerHTML =document.getElementById("myDiv").style.backgroundColor;
}
</script>

</body>
</html>



PreviousNext

Related