Using different position types: - Javascript CSS Style Property

Javascript examples for CSS Style Property:position

Description

Using different position types:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Select a position in the list below to change the div's position.</p>

<div id="myDiv" style="top:50px;left:100px;">I am a div element.</div>

<select onchange="myFunction(this);" size="5">
  <option>absolute
  <option>fixed
  <option>static
  <option>relative
  <option>sticky
</select>//from w w w. j  a v  a  2s.co  m

<script>
function myFunction(x) {
    var whichSelected = x.selectedIndex;
    var posVal = x.options[whichSelected].text;
    var elem = document.getElementById("myDiv");
    elem.style.position = posVal;
}
</script>

</body>
</html>

Related Tutorials