Posts /

높이가 가장 긴 값 찾기

Twitter Facebook Google+
14 Feb 2019

높이가 가장 긴 값 찾기

가상 엘리멘트와 data 속성을 사용

html
<ul id="aaa">
 <li style="float:left; height:500px; background:#F00;">1</li>
 <li style="float:left; height:200px;  background:#0F0;">2</li>
 <li style="float:left; height:300px; background:#00F;">3</li>
</ul>

css
li {
  width: 100px
}

js
  $(document).ready(function() {
    var max_h = 0;
    $("#aaa li").each(function() {
      var h = parseInt($(this).css("height"));
      if (max_h < h) { 
        max_h = h;
      }
    });
    $("#aaa li").each(function() {
      $(this).css({
        height: max_h
      });
    });
  });

결과

jsfiddle에서 보기


Twitter Facebook Google+