开发者

Why isn't obj.style.left = "200px"; working in this code?

开发者 https://www.devze.com 2023-01-25 14:33 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号