Jquery auto numbering based on class div, but reset counter on specified div
<p>I have a problem with this JQUERY numbering, all I want just reset counter of green tables data, first tables data is good 1),2),3) but next tables data is 4),5),6) I want to reset it to 1),2),3),4) and so on for the green tables data</p>

<p>The code I used in javascript is</p>

<pre><code>            var num1=1,num2=1,num3=1,num4=1;
            $(".lv0name").each( function() {$(this).text(romanize(num1)  +". "+ $(this).text());num1++;});
            $(".lv1name").each( function() {$(this).text(num2 +". "+ $(this).text());num2++;});
            $(".lv2name").each( function() {$(this).text(num3 +"). "+ $(this).text());num3++;});
            $(".lv3name").each( function() {$(this).text(num4 +". "+ $(this).text());num4++;});
</code></pre>

<p>Part of the code is </p>

<pre><code>&lt;table border="1" id="tabletabular" class="tablenum"&gt;
&lt;tr&gt;
    &lt;td bgcolor="blue" class="lv0name" id="root40" style="padding-left: 20px;"&gt;Luas Wilayah&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td bgcolor="yellow" class="lv1name" style="padding-left: 40px;"&gt;Daratan&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td bgcolor="yellow" class="lv1name" style="padding-left: 40px;"&gt;Laut 12 Mil dari Darat&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td bgcolor="yellow" class="lv1name" style="padding-left: 40px;"&gt;Zona Laut&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
    &lt;td bgcolor="green" class="lv2name" style="padding-left: 60px;"&gt;Laut Teritorial&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td bgcolor="green" class="lv2name" style="padding-left: 60px;"&gt;Zona Ekonomi Ekslusif&lt;/td&gt;  
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td bgcolor="green" class="lv2name" style="padding-left: 60px;"&gt;Laut Landasan Kontinen&lt;/td&gt;
&lt;/tr&gt;

&lt;tr&gt;
    &lt;td bgcolor="yellow" class="lv1name" style="padding-left: 40px;"&gt;Panjang Garis Pantai&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td bgcolor="blue" class="lv0name" id="root41" style="padding-left: 20px;"&gt;Topografi&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td bgcolor="yellow" class="lv1name" style="padding-left: 40px;"&gt;Luas Lahan Berdasarkan Kelas Lereng&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td bgcolor="green" class="lv2name" style="padding-left: 60px;"&gt;Datar (0-2 Derajat)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td bgcolor="green" class="lv2name" style="padding-left: 60px;"&gt;Bergelombang (2-15 Derajat)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td bgcolor="green" class="lv2name" style="padding-left: 60px;"&gt;Curam (15-40 Derajat)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
    &lt;td bgcolor="green" class="lv2name" style="padding-left: 60px;"&gt;Sangat Curam (&amp;gt;40 Derajat)&lt;/td&gt;
&lt;/tr&gt;
</code></pre>

<p></p>

<p>Here is the screenshot</p>

<p><a href="https://i.stack.imgur.com/fRlXu.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fRlXu.png" alt="Table auto numbering with jquery"></a></p>

<p>Regard</p>