jQuery - set div width to sum of it's children

前端 未结 1 597
鱼传尺愫
鱼传尺愫 2020-12-16 02:21

I have following setup:

html:

相关标签:
1条回答
  • 2020-12-16 02:49
    var sum=0;
    $('#holder img').each( function(){ sum += $(this).width(); });
    $('#holder > div').width( sum );
    
    //alert(sum);
    

    this should do the trick ..

    The float to the images, you can apply it with css

    #holder img{float:left;}
    
    0 讨论(0)
提交回复
热议问题