admin 管理员组文章数量: 1086019
I don't know why it can't find the height. Any help would be appreciated.
var h = document.getElementById('big_button').clientHeight,
center = -h / 2;
window.onload = function () {
document.getElementById('big_button_container2').style.marginTop = 'center';
};
/
I don't know why it can't find the height. Any help would be appreciated.
var h = document.getElementById('big_button').clientHeight,
center = -h / 2;
window.onload = function () {
document.getElementById('big_button_container2').style.marginTop = 'center';
};
http://jsfiddle/4zux6/
Share Improve this question asked Jan 19, 2014 at 1:25 dillonbrannickdillonbrannick 3221 gold badge5 silver badges17 bronze badges 4-
1
You have no element with the ID
big_button
. – cookie monster Commented Jan 19, 2014 at 1:27 -
Needs semicolon
;
after clientHeight instead of ma,
? – John McMahon Commented Jan 19, 2014 at 1:28 -
@JohnMcMahon: The
,
is correct. It's declaring multiple variables. – cookie monster Commented Jan 19, 2014 at 1:28 - @cookiemonster can't believe I missed that, I must be quite tired – dillonbrannick Commented Jan 19, 2014 at 1:42
1 Answer
Reset to default 2You can use document.getElementsByClass instead as you have only elements with class names not IDs.
i.e.
var h = document.getElementsByClassName('big_button')[0].clientHeight,
center = -h / 2;
window.onload = function () {
document.getElementsByClassName('big_button_container2')[0].style.marginTop = 'center';
};
本文标签: javascriptUncaught TypeError Cannot read property 39clientHeight39 of nullStack Overflow
版权声明:本文标题:javascript - Uncaught TypeError: Cannot read property 'clientHeight' of null - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/p/1744024038a2520314.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论