dillonbrannick
dillonbrannick

Reputation: 322

Uncaught TypeError: Cannot read property 'clientHeight' of null

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.net/4zux6/

Upvotes: 2

Views: 30964

Answers (1)

Andrew Robinson
Andrew Robinson

Reputation: 356

You 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';
};

Upvotes: 2

Related Questions