Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

jquery count 2 values in the table..?

i want to count the value in my table and put the result to a div inside my Html document.

What i have is the following code:

    var counter = 0;
$(document).ready(function(){
    $('Table td').each(function(){
        if ($(this).text() === "Nicht aktiv") counter++; 
        $("#log2").html("Nicht in Arbeit " + counter);
    });
});

I want to check:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

if this text === "Nicht aktiv" and
if this text in another td is Test1

Jquery or Javascript are not my main languages so i dont know, how i can solve this..

I hope you guys can help me.. 🙂

>Solution :

You likely mean

$(function() {
  const counter = $('table td')
    .filter(function() {
      return $(this).text() === "Nicht aktiv" &&
        $(this).siblings().filter(function() {
          return $(this).text() === "Test1"
        }).length > 0;
    }).length
  $("#log2").html("Nicht in Arbeit " + counter);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<span id="log2"></span>
<table>
  <tr>
    <td>Nicht aktiv</td>
    <td>Bla</td>
    <td>Test1</td>
  </tr>
  <tr>
    <td>Nicht aktiv</td>
    <td>Bla</td>
    <td>Test2</td>
  </tr>
  <tr>
    <td>Nicht aktiv</td>
    <td>Bla</td>
    <td>Test1</td>
  </tr>
  <tr>
    <td>Nicht aktiv</td>
    <td>Bla</td>
    <td>Test2</td>
  </tr>
  <tr>
    <td>Nicht aktiv</td>
    <td>Bla</td>
    <td>Test1</td>
  </tr>
</table>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading