Why isn't obj.style.left = "200px"; working in this code?
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>开发者_JS百科
<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
精彩评论