tags:

views:

60

answers:

2

Hi, I have a table and i want to count how many tr i hide.

The code:

<rich:jQuery query="ready(function() {
var i = 0;
jQuery('#inbox:_inboxTable_').find('span[title=isArchivedStatusPlusIncludeArchive]').each(function(i, o){
  if (jQuery(this).text() == 'true+false' ){
             i++;
             alert(i);
             jQuery(this).parent().parent().parent().fadeOut();
  }
 jQuery('#inbox').find('span[title=documentProccesedCountTitle]').html(i+' documents are beeing processed to be removed from the inbox');
});
})"/>

For a page with 10 tr, in my test 7 are hidden by this part of code but 'i' is 10 instead of 7 at the last step...

I just have no clue...why? Does anyone see the reason?

Thanks in advance.

+2  A: 

What about:

$("#table_id tr:hidden").length
Fabian Vilers
There are others tr hidden as well, so i cannot count on this solution.
Cristian Boariu
+1  A: 

i=10 because you are using it as an index of the function, try using j or something else:

jQuery('#inbox:_inboxTable_').find('span[title=isArchivedStatusPlusIncludeArchive]').each(function(j, o){
...
}

Also, instead of using jQuery(this).parent().parent().parent().fadeOut(); you could use the closest jQuery(this).closest('tr').fadeOut(); (if the tr is your target).

fudgey
I knew that was something small:) Thanks a lot.
Cristian Boariu
And about the 2nd part of your answer: closest('tr') has harmfull behaviour in Firefox.
Cristian Boariu
I've never had problems using `closest`, what problems are you experiencing or have you heard of? I'm curious.
fudgey
Cristian Boariu