2

As shown in the image below, I have several div inside a div (outer div). I need to count the number of rows the outer div have. In this example the row count is 5.

Note:The inner div is floated left and its content is created dynamically.

Does anyone has any ideas?enter image description here

Pinoy2015
  • 1,429
  • 15
  • 29

2 Answers2

1

Perhaps something along the lines of:

Demo Fiddle

var minLeft = null, rows = 0;
$('div div').each(function () {
    var left = $(this).offset().left;
    if (left <= minLeft || minLeft==null) {        
        rows++;
        minLeft=left;
    }
});
console.log(rows);
SW4
  • 69,876
  • 20
  • 132
  • 137
1

Try with something like this:

var parentX = $('#containerDiv').position().left;
var rows = 0;

$('#containerDiv div').each(function(){
  if( $(this).position().left == parentX ){
    ++rows;
  }
});

alert('Num of rows: ' + rows );
TheGr8_Nik
  • 3,080
  • 4
  • 18
  • 33