I'm using Bootstrap to create tabs when a link in a treeview is clicked. Within each tab that opens on a click there are two other tabs called Query Builder and Dimension Builder. Below is the markup that's created on the go with jQuery (just part of it):

```
<div class="tab-pane active" id="1" role"tabpanel">
    <ul class="nav nav-tabs query-dimension-tabs" role="tablist">
        <li role="presentation" class="active">
            <a role="tab" data-toggle="tab" href="#tab0" aria-controls="tab0">Query Builder</a>
        </li>
        <li role="presentation">
            <a role="tab" data-toggle="tab" href="#tab1" aria-controls="tab1">Dimension Builder</a>
        </li>
    </ul>
    <div class="tab-content"></div>
</div>
<div class="tab-pane" id="2" role"tabpanel">
    <ul class="nav nav-tabs query-dimension-tabs" role="tablist">
        <li role="presentation" class="active">
            <a role="tab" data-toggle="tab" href="#tab1" aria-controls="tab1">Query Builder</a>
        </li>
        <li role="presentation">
            <a role="tab" data-toggle="tab" href="#tab2" aria-controls="tab2">Dimension Builder</a>
        </li>
    </ul>
    <div class="tab-content"></div>
</div>

```

To be able to have my forms, one for Query Builder and one for Dimension Builder, within these tabs and keep each form unique from the other in each tab within each tab-pane all of those `<a>` tags need to have unique href and aria-controls attributes, that is the number on the end has to be unique. So the first `<a>` tag needs to be number 0, next number 1, 2, 3, 4.... and so on.

I'm using a for-loop to loop through all `<ul>` that exist and I'm trying to set the number for two `<a>` tags in each `<ul>`. Below is the for-loop:

```
    var contentUl = firstContentDiv.find(".query-dimension-tabs");      

    for (var i = 0; i < contentUl.length; i++) {      
        var qId = i;
        var dId = i + 1;        

        qA.href = "#tab" + qId;
        qA.setAttribute("aria-controls", "tab" + qId);
        dA.href = "#tab" + dId;
        dA.setAttribute("aria-controls", "tab" + dId);
    }

```

I've tried many different calculations but I always end up with 0 1 1 2 2 3, but I would like to have it 0 1 2 3 4 5....to how ever many tabs that have these two tabs are.

Is this possible with some calculations?

Here is a photo of the tabs when two links have been clicked:

[![enter image description here](https://i.stack.imgur.com/gLxNl.png)](https://i.stack.imgur.com/gLxNl.png)