Find out divs height and setting div height

后端 未结 9 943
天涯浪人
天涯浪人 2020-12-14 21:41

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

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 21:59

    You can use jQuery's height method to get and set the height of an element.

    You need to loop through the elements, find the tallest one, then set the height of all of the elements.

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

    Replace 'div' with a jQuery selector that selects the elements you want to equalize.

提交回复
热议问题