admin管理员组文章数量:1134574
Is it possible to set width or height of HTML element (ex. <div>
) in JavaScript in Standards Mode?
Note the following code:
<html>
<script language="javascript" type="text/javascript">
function changeWidth(){
var e1 = document.getElementById("e1");
e1.style.width = 400;
}
</script>
<body>
<input type="button" value="change width" onclick="changeWidth()"/>
<div id="e1" style="width:20px;height:20px; background-color:#096"></div>
</body>
</html>
When user presses the change width button, the <div>
's width should change.
It works fine when doctype declaration determines Quirks Mode. In Standards Mode I'm unable to change the element's size this way
Is it possible to manipulate the size of an element in Standards Mode? How to bypass this disfunctionality?
Is it possible to set width or height of HTML element (ex. <div>
) in JavaScript in Standards Mode?
Note the following code:
<html>
<script language="javascript" type="text/javascript">
function changeWidth(){
var e1 = document.getElementById("e1");
e1.style.width = 400;
}
</script>
<body>
<input type="button" value="change width" onclick="changeWidth()"/>
<div id="e1" style="width:20px;height:20px; background-color:#096"></div>
</body>
</html>
When user presses the change width button, the <div>
's width should change.
It works fine when doctype declaration determines Quirks Mode. In Standards Mode I'm unable to change the element's size this way
Is it possible to manipulate the size of an element in Standards Mode? How to bypass this disfunctionality?
Share Improve this question edited Mar 5, 2016 at 15:37 Jonathan Hall 79.4k18 gold badges158 silver badges201 bronze badges asked Jan 12, 2011 at 10:23 rafalryrafalry 2,6706 gold badges24 silver badges39 bronze badges2 Answers
Reset to default 244Try declaring the unit of width:
e1.style.width = "400px"; // width in PIXELS
The style
property lets you specify values for CSS properties.
The CSS width
property takes a length as its value.
Lengths require units. In quirks mode, browsers tend to assume pixels if provided with an integer instead of a length. Specify units.
e1.style.width = "400px";
本文标签: javascriptSet element width or height in Standards ModeStack Overflow
版权声明:本文标题:javascript - Set element width or height in Standards Mode - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736838648a1955001.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论