https://i.sstatic.net/uyjPk.pngI'm currently working on a task that involves summing up the number of listeners from various servers. These values are stored within a div with the id="channel1", and each number of listeners is located in a span element with the class stats. My goal is to collect all these values with the class 'stats' inside the div with the id 'channel1'.
Here is the HTML and jQuery code snippet:
<div class="panel-body" id="channel1">
<div id="kanali1-a">
<h4>Server 1*</h4>
<span> IP: 85.93.88.146 Port: 8000</span>
Currently Listening: <span class="stats badge"></span><br>
<span>This is the main server where the transmission takes place.</span>
</div>
<div id="kanali1-b">
<h4>Server 2</h4>
<span> IP: 85.93.88.146 Port: 8004</span>
Currently Listening: <span class="stats badge">10</span><br>
<span></span>
</div>
(Rest of the server details skipped for brevity)
</div>
jQuery Code:
var statsCh1 = $('#channel1 .stats').text();
var resCh1 = 0;
for (var i=0; i<statsCh1.length; i++){
resCh1 += statsCh1[i] << 0;
//console.log(statsCh1[i]);
}
$('#kanal1Total').text(resCh1);