Java Script


JavaScript Tutorial


Admission Enquiry Form


How to get name of backgoungcolor of a Div?

Example :

<html>
<head>
<title>Get Colour of Div</title>
<style>
h2{background-color:lightgrey;}
</style>
<script>

function getcolor()
{
var x=document.getElementById("mydiv").style.backgroundColor;
document.getElementById("my_heading").innerHTML="The div is of "+x+" color";
}
</script>
</head>
<body>
<h2>Get the color of div by clicking on Button</h2>
<div style="background-color:red; height:200px; width:200px;" id="mydiv"></div><br><br>
<input type="button" value="click" onClick="getcolor()">
<h2 id="my_heading"></h2>
</body>
</html>

Get Colour of div

Q6.Get the color of div by clicking on Button