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: 
`reduce` over the colspan info.

```
var th = document.querySelectorAll('table thead tr:first-child th');

var cols = [].reduce.call(th, function (p, c) {
  var colspan = c.getAttribute('colspan') || 1;
  return p + +colspan;
}, 0);

```

[DEMO](https://jsfiddle.net/toahb3a3/3/)
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/)