John John
John John

Reputation: 1

how to remove a TR which have a TD that contain specific text

I have the following markup which have SPAN >> Table >> TR >> TD:-

enter image description here

now i want to specify either using css or jquery to remove the TR which have a TD that contain the word "Question" inside <nobr> tag. so can anyone adivce how i can do so ? thanks

Upvotes: 4

Views: 2035

Answers (4)

Placid
Placid

Reputation: 1448

You can do it with jQuery as shown below:

$(document).ready(function(){
    $('td').each(function(){
        if($(this).find('nobr').text() === 'Question') {
            $(this).closest('tr').remove();
        }
    });
});

Upvotes: 1

Anand G
Anand G

Reputation: 3200

It would have been helpful if you could provide HTML. I would have created fiddle but You can try below solution

Iterate tr in table and find the tr having

   $("table.ms-formtable > tbody > tr").each(function(){
       var text = $(this).find("td:first").find("nobr").text();
       if(text === 'Question') {
          $(this).remove();
       }
   });

http://jsfiddle.net/9tw2kfek/

Upvotes: 0

Rajaprabhu Aravindasamy
Rajaprabhu Aravindasamy

Reputation: 67207

Try to use :has() selector along with :contains() selecor to achieve what you want,

$("tr:has(td nobr:contains('Question'))").remove();

DEMO

Upvotes: 1

CodingIntrigue
CodingIntrigue

Reputation: 78545

You can use filter to compare the exact text of the <nobr> element, then remove the closest <tr>

$("span table tr td nobr").filter(function() {
  return $(this).text() === "Question";
}).closest("tr").remove();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<span>
  <table>
    <tr>
      <td>
        <h3>
          <nobr>Question</nobr>
        </h3>
      </td>
    </tr>
    <tr>
      <td>
        Untouched
      </td>
    </tr>
    
  </table>
</span>

Upvotes: 3

Related Questions