Why wont .style.top = "200px"; work in this code? Calling the event within the element using oclick="this.style.left='200px';" doesn't work either.
<html>
<head>
</head>
<body>
<div id="theDiv">The Div</div>
<button id="theButton">Do</button>
</body>
</body>
</html>
<script type="text/javascript">
document.getElementById("theButton").onclick = function(){
document.getElementById("theDiv").style.top = "200px";
};
</script>
To use a left or top style the element must be position:absolute, or position:relative, or position:fixed
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With