Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
196 views
in Technique[技术] by (71.8m points)

javascript - Find out divs height and setting div height

I'm quite new to javascript/jquery stuff, but i would like to do this kind of thing with it:

I have four divs side-by-side like this and content in each one. Now if one has more content it gets stretched higher. I would like to make the other divs as high too even if they don't have as much content. So basically i want the script goes through the divs and check the heights and sets all of divs heights to same as the highest div has. Hopefully you understand :)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I was getting a NaN error with SLaks code. Giving maxHeight an initial value of 0 did the trick.

var maxHeight = 0;
$('div')
  .each(function() { maxHeight = Math.max(maxHeight, $(this).height()); })
  .height(maxHeight);

Thanks SLaks!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...