tags:

views:

420

answers:

4

if i have a table like this

<table width="500"  border="0" style="border:0px;" id="options">
<tr>
<td>Designers</td>
<td><input type="checkbox">
</tr>
</table>

how would i hide the row with designers?

i was guess it would look something like this

$(document).ready(function() {
  if( $('table #options tr td').html('Designers') {
  $(this).css('display','none');
  }
  });

but am not sure

thanks

+6  A: 

This should do it, assuming when you said "row" you meant the <tr>, not the <td>:

$(document).ready(function() {
    $('td', '#options').filter(function() { // select all the TDs
        return $(this).text() == 'Designers'; // keep the ones that have
                                              // 'Designers' as their HTML
    }).each(function() { // loop through each of the ones that matched
        $(this).closest('tr').hide(); // find the parent tr and hide it
    });
});

If you just want to hide the actual <td> (which is not a row, but a cell) then you would do this:

$(document).ready(function() {
    $('td', '#options').filter(function() { // select all the TDs
        return $(this).text() == 'Designers'; // keep the ones that have
                                              // 'Designers' as their HTML
    }).hide();
});

Hiding table cells is in questionable taste, though...

Paolo Bergantino
A better way to determine the content would be to use $(this).text() instead of $(this).html(). That way, if the td element contains "<strong>D</strong>esigners", the element would still match. Which in my opinion is the Right Thing.
kizzx2
That's a fair point. Edited.
Paolo Bergantino
+2  A: 
$("td:contains('Designers')").hide();
kizzx2
That would hide just the cell, not the entire row, and it would match any cells that contain it at any point, I think he wants an exact match
Paolo Bergantino
Based on his code, we might say he wanted exact match. But obviously his code shows that he can't expressively say what's the exact requirements, through his code (for the very reason he's asking :p)So we looked at the title in English:hide _td_ elements with a specific word _in_ themNot trying to cherry pick or something. I thought that's just what he wanted.
kizzx2
True. Hard to tell.
Paolo Bergantino
A: 

Hi. Here goes. straight from http://docs.jquery.com/Selectors/contains#text

$("td:contains('Designer')").css("display", "none");
Giggy
A: 

what if i want to to remove the word dsigner and replace it by another or just remove it? thanks