0

I have four divs with different IDs. How would I set height for all these divs?

<div id="slide-1">a</div> <div id="slide-2">b</div> <div id="slide-3">c</div> <div id="slide-4">d</div> 

I know we can do something like this below, but there are other divs too before this.

$('div').height($(window).height()); 

I want to set these four divs to window height alone. I can't hard-code here as the slides may vary.

1
  • instead of $('div').height($(window).height()); put the div id $('#slide-1').height($(window).height()); for example Commented Jul 22, 2014 at 16:39

5 Answers 5

3

this will select all the divs that their ids start with "slide-" and set the height to window height:

$('div[id^="slide-"]').height($(window).height()); 
Sign up to request clarification or add additional context in comments.

1 Comment

And fiddle for this: jsfiddle.net/f3C3V. Also please replace $(window).height with $(window).height() to make answer correct
2
$('div[id^="slide-"]').css("height", $(window).height() + 'px'); 

Demo:

http://jsfiddle.net/463KU/1/

1 Comment

It will set height for all DIVs on page. OP talked about only selected 4 DIVs
1

DEMO

 $('div').filter(function() { return /^slide-[1-4]$/.test( this.id ); }) .height( $(window).height() ); 

Comments

0

if you like to increase the hieght of specific divs use class for multiple

<div class="divHeight" id="slide-1">a</div> <div class="divHeight" id="slide-2">b</div> <div class="divHeight" id="slide-3">c</div> <div class="divHeight" id="slide-4">d</div> $('.divHeight').height($(window).height()); 

Comments

0

I also recommended you use this way to get window height:

var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight; <div class="divHeight" id="slide-1">a</div> <div class="divHeight" id="slide-2">b</div> <div class="divHeight" id="slide-3">c</div> <div class="divHeight" id="slide-4">d</div> $('.divHeight').height(windowHeight); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.