Question: I would like to set a specific color on the circle of bubble chart in terms of a variable. I can change all the bubble in red for example but not each bubble. My condition is an attribute of d and it define by the content of my JSON.

```
node.append("circle")
        .attr("r", function(d) { return d.size; })
        .style("fill", "red"); // all my bubble are red but the condition doesn't works
        /* 
        if (condition) {
          .style("fill", "red");
        } else {
          .style("fill","green");
        }
        */

```

This is the Plunker project : <https://plnkr.co/edit/07RZFQoBrBz2xWxmiCl0?p=preview>
Thanks.

Answer: 
To calculate the number of columns in a table, you need to find the row with the most columns in it. To do that, you need to test each row in turn, but take into account any cells from previous rows that span into it.

This should do the trick.

```
// Store the cells in each row
var rows = [];

function increment_row(index, amount) {
    if (rows[index]) {
        rows[index] += amount;
    } else {
        rows[index] = amount;
    }
}

// Count the cells in each row
$("tr").each(function (row_index, row_element) {
    var $row = $(row_element);
    $row.children().each(function (cell_index, cell_element) {
        var $cell = $(cell_element);
        var row_count = parseInt($cell.attr("rowspan"), 10) || 1;
        var col_count = parseInt($cell.attr("colspan"), 10) || 1;
        for (var i = 0; i < row_count; i++) {
             increment_row(row_index + i, col_count);        
        }
    })
});

// Find the row with the most cells
var sorted = rows.sort();
console.log(sorted[sorted.length - 1]);

```
Hunh, The deadliest way is either use [**`jQuery .filter`**](http://api.jquery.com/filter/) or [**`jQuery Attribute Selector`**](https://api.jquery.com/attribute-equals-selector/)

**`If you want this should be for all who has digits only use this:`**

```
$(function() {
  // Get total no of rowspan or colspan, if attr has numbers
  var NoOfColumnHasRowSpanOrColSpan = $('th').filter(function() {
    // check if attr exist
    var _rowspan = $(this).attr('rowspan');
    var _colspan = $(this).attr('colspan');
    // check if not undefined
    if (typeof _rowspan !== typeof undefined && _rowspan !== false) {
      // return if attr has value as number
      return /[0-9]/.test(_rowspan);
    }
    // same as above
    if (typeof _colspan !== typeof undefined && _colspan !== false) {
      return /[0-9]/.test(_colspan);
    }
  }).length;
  // get no of count th who has rowspan or colspan and digit as value
  alert(NoOfColumnHasRowSpanOrColSpan);
});

```

**`If you don't mind values:`**

```
$(function() {
  // Get total no of rowspan or colspan
  var NoOfColumnHasRowSpanOrColSpan = $('th[rowspan],th[colspan]').length;
  // get no of count th who has rowspan or colspan
  alert(NoOfColumnHasRowSpanOrColSpan);
});

```

[**Run DEMO:**](https://jsfiddle.net/neerajsinghsonu/20cd27ks/)