I need to move div on click of one of the 4 buttons: left, right, top, bottom
By clicking on each button I want div to move to the left, right, top, bottom according to the clicked button.
function left(){
$( "#rstSearch" ).position().left = $( "#rstSearch" ).position().left + 10;
}
function right(){
$( "#rstSearch" ).position().right = $( "#rstSearch" ).position().right + 10;
}
function top2(){
$( "#rstSearch" ).position().top = $( "#rstSearch" ).position().top + 10;
}
function bottom(){
$( "#rstSearch" ).position().bottom = $( "#rstSearch" ).position().bottom + 10;
}
#rstSearch {
background-color: blue;
width:50px;
height:50px;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button type="button" id="btnLeft" onclick="left();" class="button_air-medium"> left</button>
<button type="button" id="btnRight" onclick="right();" class="button_air-medium">right</button>
<button type="button" id="btnTop" onclick="top2();" class="button_air-medium">top</button>
<button type="button" id="btnBottom" onclick="bottom();" class="button_air-medium">bottom</button>
<div id="rstSearch" class="exosphere" ></div>
As you can see each button has an event listener that calls a function to move the div to said direction.
This however does not work, what do I have change to make it work?