I try to change the background color of my whole page, on click on my div with id main
. Here is my code:
$(document).ready(function() {
var color = 1;
$('#main').click(function(){
if (color == 1) {
$(this).css("background-color", "green");
color = 2;
} else if (color == 2) {
$(this).css("background-color", "black");
color = 1;
}
});
});
#admin_div {
position: absolute;
width: 80%;
height: 80%;
border: 2px solid white;
border-radius: 10px;
background-color: #D9D9D9;
z-index: 1;
}
h1 {
margin-left: 15px;
}
#main {
height: 100%;
width: 100%;
z-index: 0;
}
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<div id="main">
<div id="admin_div">
<h1>Admin Panel</h1>
</div>
</div>
But the background color is also changing if i click on another element than main. I think it is because everything is inside the main div.