jQuery - add different ids to next sibling
<p>The following code adds the same ID to every div sibling:</p>

<pre><code>var d = 0;
var newid = currentId.substring(currentId.length-8, currentId.length-1)+d;

$.each(('table').next(), function() {
    $('table').find('div[id|="edid"]').attr("id", newid);   
    d++;
});
</code></pre>

<p>The HTML structure looks like this:</p>

<pre><code>&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;div id="edid-0-"&gt;text&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;br&gt;
&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;div id="edid-0-"&gt;text&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;br&gt;
&lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;div id="edid-0-"&gt;text&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
</code></pre>

<p>After running my code, the IDs should look like: <code>edid-0-0</code>, <code>edid-0-1</code>, <code>edid-0-2</code>, and so on.</p>

<p>But instead, all are either <code>edid-0-0</code>, <code>edid-0-0</code>, <code>did-0-0</code>...
                         or <code>edid-0-3</code>, <code>edid-0-3</code>, <code>edid-0-3</code>...</p>

<p>depending on where i put the variables (in or outside the each function).</p>

<p>I tried various variations, but it's always the same ID ending, und no continuing numberation. I kind of understand why this happens, but I have no clue on how solving this problem. Sitting here for hours. My head -> explodes.</p>
