Hi, I have been given a correct answer on a very similar question, but I have missed this detail that I can not solve ... how to add the elements of the same class from a group of tables ...
Example:
JSFiddle
HTML:
<table>
<tr>
<td id="tabela">
<input type="text" id="tabelainput" class="janmembros" maxlength="3" name="janmembros" value="1" disabled>
</td>
<td id="tabela">
<input type="text" id="tabelainput" class="janvisitantes" maxlength="3" name="janvisitantes" value="3" disabled>
</td>
<td id="tabela3" class="jantotal">
</td>
</tr>
</table>
<table>
<tr>
<td id="tabela">
<input type="text" id="tabelainput" class="janmembros" maxlength="3" name="janmembros" value="1" disabled>
</td>
<td id="tabela">
<input type="text" id="tabelainput" class="janvisitantes" maxlength="3" name="janvisitantes" value="2" disabled>
</td>
<td id="tabela3" class="jantotal">
</td>
</tr>
</table>
<table>
<tr>
<td id="tabela">
<input type="text" id="tabelainput" class="janmembros" maxlength="3" name="janmembros" value="1" disabled>
</td>
<td id="tabela">
<input type="text" id="tabelainput" class="janvisitantes" maxlength="3" name="janvisitantes" value="5" disabled>
</td>
<td id="tabela3" class="jantotal">
</td>
</tr>
</table>
<table>
<tr>
<td id="tabela">
</td>
<td id="tabela">
</td>
<td id="tabela3" class="total">
</td>
</tr>
</table>
JQuery:
if ( $( ".janmembros" ).val() != '' && $( ".janvisitantes" ).val() != '' )
{
$('table').each(function() {
var $this = $(this),
janmembros = parseInt($this.find( ".janmembros" ).val()),
janvisitantes = parseInt($this.find( ".janvisitantes" ).val());
$this.find( ".jantotal" ).html( janmembros+janvisitantes );
$( ".total" ).html($this.find( ".jantotal" ).html()); // essa linha deveria somar todos as classes .jantotal, mas só soma a última...
});
}
EDIT:
After the help of @Sergio I was still unable to solve the problem, follow the JSFiddle with new information of the problem: JSFiddle
There are two divs with the tables inside and I need the sum of each of the divs ... I need to skip to the next sum of the next div!