jQuery Loop through each div

后端 未结 5 880
暗喜
暗喜 2021-02-05 15:10

I\'m pretty sure this will be a really easy answer for you jQuery whizzes, and I\'m also pretty such it involves a loop of some kind.

I\'m trying to perform essentially

5条回答
  •  萌比男神i
    2021-02-05 15:43

    $('div.target').each(function() {
       /* Measure the width of each image. */
       var test = $(this).find('.scrolling img').width();
    
       /* Find out how many images there are. */
       var testimg = $(this).find('.scrolling img').length;
    
       /* Do the maths. */
       var final = (test* testimg)*1.2;
    
       /* Apply the maths to the CSS. */
       $(this).find('scrolling').width(final); 
    });
    

    Here you loop through all your div's with class target and you do the calculations. Within this loop you can simply use $(this) to indicate the currently selected

    tag.

提交回复
热议问题