Liam
Liam

Reputation: 9855

Set height of all divs using Javascript

Im trying to set the height of all my divs with class page to 100% of the browser window...

I have the following only nothing happens and i get no errors in the console, I'm aware I could do this with jquery only my aim is to do it solely with JS.

var elements = document.querySelectorAll('page');
Array.prototype.forEach.call(elements, function(el, i){
    elements.style.height = document.getElementsByTagName(window).height;
});

Upvotes: 0

Views: 133

Answers (1)

tommybananas
tommybananas

Reputation: 5736

A couple different things wrong here:

  • You can now use document.getElementsByClassName
  • You want to use el instead of element in your forEach block
  • Using window.innerHeight for the window height

Solution

var elements = document.getElementsByClassName('page');
Array.prototype.forEach.call(elements, function(el, i){
    el.style.height = window.innerHeight+'px';
});

http://jsfiddle.net/VrdwN/

Upvotes: 1

Related Questions