javascript - How to check equality between cells in table using jQuery -


i have n-column table m-rows. want check equality between each cell in row. idea store each value in 2 dimensional array , run 'for loop' check if values equal think solution not efficient. storing cell values nth-child selector , put them temporary array. know more faster , easier solution? need compare m-values of each column , if values different row should removed table.

for example:

enter image description here

and after running "check differences" function result should be:

enter image description here

table built div's

<div class="provider">     <div class="row">1000</div>     <div class="row">1500</div>     <div class="row">1120</div> </div> <div class="provider">     <div class="row">1000</div>     <div class="row">1200</div>     <div class="row">1120</div> </div> <div class="provider">     <div class="row">2200</div>     <div class="row">1700</div>     <div class="row">1120</div> </div> <div class="provider">     <div class="row">3700</div>     <div class="row">3300</div>     <div class="row">1120</div> </div> 

and part of js:

for(j = 0; j < rowscounter; j++) {     (i = 0; < colscounter; i++) {         buf[j][i] = $('.provider:nth-child(' + + ') div:nth-child(' + j + ')').text();     } } 

next part same running buf array , checking equality of values..

to more scalable approach, can use this:

var buf=[];  $('.provider').each(function(){     var rows=[];     $('.row', this).each(function(){         rows.push( parseint( $(this).text().trim() ));     });     buf.push(rows); }); 

ideally, should never suppose "all children" or "all somewhere" part of elements want handle. best aware of exact elements need. in case, .row nested in .provider.

take @ working fiddle.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -