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
LVL 3
Neil ThompsonSenior Systems DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
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

0
Neil ThompsonSenior Systems DeveloperAuthor Commented:
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;">
0
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
1) Get the value of the text area:  var txtAuthUser = $('textarea#ctl00_txtAuthenticatedUser').text();

2) If the variable txtAuthUser='' then run a function to hide the rows as described.

http://jsbin.com/xunumu/edit?html,output
<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
  <script>
    $(function() {
    var txtAuthUser = $('textarea#ctl00_txtAuthenticatedUser').text();

    if (txtAuthUser === "") {
        hideProcessName();
    }

    function hideProcessName() {
        $("a[href*='ProcessName=nr']").closest("tr").hide();
    }
});
  </script>
  <meta charset="utf-8">
  <title>experts-exchange.com/questions/28695560</title>
</head>
<body>
<textarea name="ctl00$txtAuthenticatedUser" rows="2" cols="20" readonly="readonly" id="ctl00_txtAuthenticatedUser" class="AuthenticatedUser" style="border-style:None;"></textarea>
  <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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Superb, thanks so much for the great, quick answer. Neil
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.