How to remove TRs that have TDs that contain specific text

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

enter image description here

now I want to specify either using css or jquery to remove TRs that have TDs that contain the word β€œQuestion” inside the <nobr> . so can anyone come up with how i can do this? thanks

+4
source share
4 answers

You can use filter to compare the exact text of the <nobr> element, then remove the nearest <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> 
+3
source

Try using the :has() selector together with :contains() selecor to achieve the desired result,

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

Demo

+1
source

You can do this with jQuery as shown below:

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

It would be helpful if you could provide HTML. I would create a fiddle, but you can try the solution below

Iterate over tr in the table and find 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/

0
source

All Articles