javascript - Subtotal Group using jquery -


fiddle

<table border="1" class="csstable">     <tr id="trgroup">         <td>             black, total <asp:label id="lblcount" runat="server"></asp:label>         </td>     </tr>     <tr>         <td class="csstd">                                    </td>     </tr>        <tr>         <td class="csstd">               b                      </td>     </tr>        <tr id="trgroup">         <td>             white, total <asp:label id="lblcount" runat="server"></asp:label>         </td>     </tr>     <tr>         <td class="csstd">               x                      </td>     </tr>        <tr>         <td class="csstd">               y                      </td>     </tr>        <tr>         <td class="csstd">              z                 </td>     </tr>        </table> 

i have subtotal group. means in above example black have 2 child , white have 3 child

change id='trgroup' class='trgroup' (you're supposed have unique id's), , use nextuntil method.

$('.trgroup').each(function () {     var $this = $(this),         subtotal = $this.nextuntil('.trgroup').length;     $this.text($this.text() + subtotal); }); 

demo


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -