Skip to content Skip to sidebar Skip to footer

Jquery: Select Identical Numbers From A Table

I have this HTML table loaded from MYSQL, every row is composed this way: 02/05/201589.30.86.72.65<

Solution 1:

Try This,

I have updated your own code, so that you can understand it easily.

functionhighlightNumbers(){
  
        var all= $("td[class*=bari]");
        var index = all.length-1;
  
        var due_serie = $(all[index]).html().split('.').concat($(all[index-1]).html().split('.'));
        //Rimuovo i doppionivar serieCompleta = [];
        $.each(due_serie, function(i, el){
            if($.inArray(el, serieCompleta) === -1) serieCompleta.push(el);
        });

        //Ottengo dati          for(var s=0;s<index-1;s++)
          {
            
            var bar = $(all[s]);
            var barnum = bar.html().split('.');
            bar.html('');

            var found = 0;

            for(i = 0; i<= barnum.length-1; i++)
             {
               for(n = 0; n<= serieCompleta.length-1; n++)
                 {
                  if(barnum[i] == serieCompleta[n])
                    {
                    bar.append('<span style="color:red">'+barnum[i]+'</span>.');
                    found = barnum[i];
                    }
                 }
               if(barnum[i] != found)
               {
                bar.append(barnum[i]+'.');
               }
             }
            
          }
  
  
}

highlightNumbers();
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><table><tr><td>02/05/2015</td><tdclass="bari1">89.10.86.30.65</td></tr><tr><td>30/04/2015</td><tdclass="bari2">96.11.73.36.13</td></tr><tr><td>02/05/2015</td><tdclass="bari3">78.34.50.72.11</td></tr><tr><td>30/04/2015</td><tdclass="bari4">34.78.69.60.22</td></tr><tr><td>02/05/2015</td><tdclass="bari5">12.29.30.69.33</td></tr><tr><td>30/04/2015</td><tdclass="bari6">59.10.20.96.44</td></tr></table>

Solution 2:

I think you could use $.inArray() function, to select only rows that contain any of the numbers in your array.

Post a Comment for "Jquery: Select Identical Numbers From A Table"