[...] isn't there a big performance impact using this piece of code?

That's why I said play around a bit ;^)  I threw that idea out there
mostly because it is sort of inside-out from style that I would
probably have tried first and it was just building off the previous
example.  That sort of thing helps me get out of a rut sometimes.  My
first stab at it would have normally been closer to Mike's #2
suggestion; a nested for loop for the td's.

Just out of curiosity is there a way to break out while iterating with
.each()? Again building on the previous example (Mike's #2 this time):

$(function() {
  $('tr').each( function() {
      var allEmpty = true;
      $('td', this).each(funcion() {
          if(this.innerHTML !== ' ' ) {
              allEmpty = false;
              // Is it possible to break out of the td.each() here?
          }
      });
      allEmpty && $(this).addClass( 'allEmptyTds' );
  });
});

Mike - Thanks but I can't take credit for mark and sweep.  I think I
got it while working on garbage collection in an OS class years ago.

On 4/27/07, Feed <[EMAIL PROTECTED]> wrote:

Thanks Ian, it seem to be working perfectly. I just have one more
question: isn't there a big performance impact using this piece of
code? It looks like the page it taking a while do load, but I guess
you have to choose between the time the page takes to load and the
time you take to do everything manually.. am I right?

On Apr 28, 1:20 am, "Ian Struble" <[EMAIL PROTECTED]> wrote:
> Building on Karl's example and your new all-td's-must-be-empty
> requirement; mark all the TR's with a target class then sweep through
> the TD's and get rid of the target class if you find a td that is not
> empty.   Play around a bit and see what else you can come up with.
>
> Ian
> ----
>
> $(document).ready(function() {
>   $('tr').addClass('allEmptyTds');    // mark
>   $('td').each(function() {
>     var $this = $(this);
>     if ($this.html() !== '&nbsp;') {
>       $this.parent().removeClass('allEmptyTds');  // and sweep
>     }
>   });
>
> });
>
> On 4/27/07, Feed <[EMAIL PROTECTED]> wrote:
>
>
>
> > Feed wrote:
> > > Hello all, I'm getting used to the excellent jQuery library and I need
> > > some help of more experienced programmers. I have this simple table:
>
> > > <table class="table">
> > >       <tr>
> > >               <td>content</td>
> > >               <td>content</td>
> > >               <td>content</td>
> > >       </tr>
> > >       <tr>
> > >               <td>&nbsp;</td>
> > >               <td>&nbsp;</td>
> > >               <td>&nbsp;</td>
> > >       </tr>
> > >       <tr>
> > >               <td>content</td>
> > >               <td>content</td>
> > >               <td>content</td>
> > >       </tr>
> > > </table>
>
> > > What I need is to add a class to the TRs that have children TDs that
> > > have &nbsp; inside (and ONLY &nbsp;)... I'm having problems because
> > > &nbps; is not text, it's html code...
>
> > > Thanks in advance!
>
> > Thanks guys, that really helped, specially Karl Swedberg's piece of
> > code. The problem is: the class must only be applied to the TR only if
> > ALL children TDs have &nbsp; inside... I'm having a hard time making
> > it work, I'm still learning how to use jQuery properly.


Reply via email to