3

Possible Duplicate:
Find text string using jQuery?

How do you find a text string and hide it with jquery.

<div class="report-box">
  <div class="title">test</div>
  <table>
    <tbody>
      <tr align="center" class="CellLabel">
        <td colspan="2">Day at a Glance</td>
      </tr>
      <tr class="CellLabel">
        <td>New Clients</td>
        <td>00000</td>
      </tr>
      <tr class="CellLabel">
      <  td>Money Received</td>
        <td>$ 0000,000.0000</td>
      </tr>
      <tr class="CellLabel">
        <td>Overdue Invoices</td>
        <td>0000000</td>
      </tr>
      <tr class="CellLabel">
        <td>Services</td>
        <td>000000</td>
      </tr>
      <tr align="right" class="CellLabel">
        <td colspan="2"></td>
      </tr>
    </tbody>
  </table>
</div>

How would I remove

<tr class="CellLabel">
  <td>Money Received</td>
  <td>$ 0000,000.0000</td>
</tr>

from the code using a jquery.

Community
  • 1
  • 1
Kenp
  • 77
  • 1
  • 2
  • 10
  • 1
    [`:contains`](http://api.jquery.com/contains-selector/) followed by `.hide()` or `.remove()`, depending on your intention. Either way, it's still in the source code, so it's just invisible, not actually deleted. – Blazemonger Jun 18 '12 at 17:31
  • Have a look at [jquery find element by text](http://stackoverflow.com/questions/7321896/jquery-find-element-by-text), [How do I remove the parent element?](http://stackoverflow.com/questions/3887648/how-do-i-remove-the-parent-element) and http://api.jquery.com/category/traversing/tree-traversal/. – Felix Kling Jun 18 '12 at 17:31
  • What you want to remove the tr or value of td? and on what condition? – Adil Jun 18 '12 at 17:45

4 Answers4

4

First off, your html is a bit messy, lacks a few tags. But here you go. ;)

1:

Preview - http://jsfiddle.net/Xpc63/1/

$('.CellLabel').removeByContent('Money');​

See preview for full JS code.

2:

Preview - http://jsfiddle.net/ahzPs/1/

$('.CellLabel').contains('Money').remove();​

See preview for full JS code.

3:

Preview - http://jsfiddle.net/mWtzw/

$('.CellLabel').filter(function() {
    return $(this).html().indexOf('Money') != -1;
}).remove();​
Community
  • 1
  • 1
Jānis
  • 328
  • 2
  • 5
0

You could use the contains selector method:

$('td:contains("$ 0000,000.0000")').parent().hide();  //to hide

$('td:contains("$ 0000,000.0000")').parent().remove();  //to remove

Or, if you just want to remove or hide the td that contains the text:

$('td:contains("$ 0000,000.0000")').hide();  //to hide

$('td:contains("$ 0000,000.0000")').remove();  //to remove
xcopy
  • 2,248
  • 18
  • 24
0
$('.cellLabel').find('td:contains("money")').remove();
micadelli
  • 2,482
  • 6
  • 26
  • 38
0
// just want to remove
$('.cellLabel').find('td:contains("Money Received")').parent.remove();

Or

 // if just want to hide
 $('.cellLabel').find('td:contains("Money Received")').parent.hide();
Nishu Tayal
  • 20,106
  • 8
  • 49
  • 101