Calculate largest width of a set of elements using jQuery

后端 未结 7 1033
轻奢々
轻奢々 2020-12-16 03:07

I have made a quick Jsbin: http://jsbin.com/ujabew/edit#javascript,html,live

What i\'m trying to achieve is to find out which is the largest

7条回答
  •  無奈伤痛
    2020-12-16 04:08

    Fleshing out Marc B's comment, using Math.max():

    $(document).ready(function(){
      var maxWidth = 0;
      $('.content ul li').each(function(){
        var itemWidth = $(this).outerWidth(true);
        maxWidth = Math.max(maxWidth, itemWidth)
      });
    });
    

提交回复
热议问题