Link to home
Start Free TrialLog in
Avatar of Neil Thompson
Neil ThompsonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

using jQuery hide an entire <tr> and its contents if the contents contain "ProcessName=nr"

Hi

I'm trying to tidy a page of which the content output I have no control over (3rd party software) but using jQuery I would like to hide any entire table rows (<tr>) and their contents if the contents of the row or column contain ProcessName=nr

For example, the following split row has ProcessName=nrMissedBin so as it contains ProcessName=nr the entire row should all be hidden:

<tr align="left" style="background-color:White;font-size:1em;">
                              <td style="width:50%;">&nbsp;</td>
                              <td><a id="ctl00_MainContent_gvwProcesses_ctl05_Hyperlink1" title="Click for the Report a missed bin collection Service" href="MapCharactersPage.aspx?servicePath=2&amp;ProcessName=nrMissedBin">Report a missed bin collection</a></td>
                            </tr>

Is this possible using jQuery please, and can someone supply the code to achieve this page wide as there could be many of them?

Thanks in advance
Neil
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

You can use $("a[href*='ProcessName=nr']").closest("tr").hide();

The *= means contains.  This code will look for an a href contains "ProcessName=nr" then hide the tr it is contained in.

http://jsbin.com/katuda/edit?html,output
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
 <script>
$(function(){
   $("a[href*='ProcessName=nr']").closest("tr").hide();
});
  </script>
  <meta charset="utf-8">
  <title>experts-exchange.com/questions/28695560/</title>
</head>
<body>
<table>
  <tr><td>good row</td></tr>
  <tr align="left" style="background-color:White;font-size:1em;">
                              <td style="width:50%;">&nbsp;</td>
                              <td><a id="ctl00_MainContent_gvwProcesses_ctl05_Hyperlink1" title="Click for the Report a missed bin collection Service" href="MapCharactersPage.aspx?servicePath=2&amp;ProcessName=nrMissedBin">Report a missed bin collection</a></td>
                            </tr>
  <tr><td>good row</td></tr>
  </table>
</body>
</html>

Open in new window

Avatar of Neil Thompson

ASKER

Wow, that's brilliant, thanks

How can I take it 1 step further and only use the above when this textarea has no content please? (as this is the only way how I know a user is logged in)

 <textarea name="ctl00$txtAuthenticatedUser" rows="2" cols="20" readonly="readonly" id="ctl00_txtAuthenticatedUser" class="AuthenticatedUser" style="border-style:None;">
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Superb, thanks so much for the great, quick answer. Neil