javascript - jQuery- counting articles in a row- it counts items from both boxes -


i'm trying count articles in top row of 2 boxes on page. boxes separate , want count -

function calculatearticlesinrow() { var articleinrow = 0; $('.promotionwrapper').each(function() {     console.log($(this).prev().length);     if($(this).prev().length > 0) {         console.log($(this).offset().top + '='+ $(this).prev().offset().top);         if($(this).offset().top != $(this).prev().offset().top){             return false;         }         articleinrow++;     }     else {         articleinrow++;        } });      $('.result1').html('no: of articles in row = ' + articleinrow); }  settimeout(function(){     calculatearticlesinrow(); }, 3000); 

the problem i'm having however, script counting articles in both boxes when articles top offset should counted.

i have found other questions this, seem use 1 box.

any appreciated.

here fiddle can see i'm trying do: https://jsfiddle.net/jackofd/de31nojn/

thanks in advance

i think should count .promotionwrapper articles each .productwrapper section.

i've updated fiddle.

var articleinrow = 0,     maxartno = 0; // cycle every .productwrapper $('.productwrapper').each(function (index, el) {     articleinrow = 0     // cycle every .promotionwrapper in .productwrapper     $('.promotionwrapper', el).each(function (innerindex, innerel) {          //your code       });     //set count max     if (articleinrow > maxartno) maxartno = articleinrow; }); // rest of code 

Comments