I have two divs as follows:
HTML:
<body>
<div id="container">
<div id="health"></div>
<div id="food"></div>
<button id="click" onClick="position();">sdcasdfzsdvv</button>
</div>
</body>
CSS :
@charset "utf-8";
*{
padding:0px;
margin:0px;}
body{
background-color:#F4F4F2;
margin-top:15px;}
#container{
width:270px;
height:162px;
margin-top:0px;
margin-left:auto;
margin-right:auto;
position:fix;}
#health{
height:80px;
margin-bottom:0px;
border: solid 1px red;
background-color:green;}
#food{
height:80px;
margin-bottom:0px;
border: solid 1px blue;
background-color:yellow;}
button{
width:100px;
height:80px;}
I want to have a function in JavaScript to move these two divs in a way that once the yellow on top and green bottom and by clicking on the button, the green moves up and yellow moves down and vice versa.
but in the first trial, the code below does not work. I don't know how to change the position of these divs without changing their positions to absolute and relative and without using jQuery. I'd be grateful if you kindly help.
function position() {
document.getElementById('health').style.top='80px';
document.getElementById('food').style.top='0px';
}