I'm trying to get a table row to hide if a certain tag has no content in it.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <body onload="myFunction()"> <script> function myFunction() { if($(this).find('SampleNumber1').length === 0 && $(this).find('TypeofTest1').length === 0 && $(this).find('PumpNumber1').length === 0 && $(this).find('CowlNumber1').length === 0 && $(this).find('SampleLocation1').length === 0 && $(this).find('SampleStart1').length === 0 && $(this).find('SampleFinish1').length === 0 && $(this).find('SampleDuration1').length === 0 && $(this).find('FlowRateStart1').length === 0 && $(this).find('FlowRateFinish1').length === 0 && $(this).find('FlowRateMinMean1').length === 0 && $(this).find('SampleVolumeLitres1').length === 0 && $(this).find('FibresCount1').length === 0 && $(this).find('GraticuleFields1').length === 0 && $(this).find('Limit1').length === 0 && $(this).find('CalculatedResult1').length === 0 && $(this).find('ReportedResult1').length === 0) { document.getElementById('Sample1').style.display = 'none'; } else { document.getElementById('Sample1').style.display = 'block'; }; } </script> <table style= width: 1300px;" border="1" cellpadding="1" cellspacing="0"> <tbody> <tr> <td colspan="1" rowspan="2" style="width: 75px; text-align: center;"><span style="font-size: 16px;">Sample Number</span></td> <td colspan="1" rowspan="2" style="width: 50px; text-align: center;"><span style="font-size: 16px;">Sample Type</span></td> <td colspan="1" rowspan="2" style="width: 60px; text-align: center;"><span style="font-size: 16px;">Pump No</span></td> <td colspan="1" rowspan="2" style="width: 60px; text-align: center;"><span style="font-size: 16px;">Cowl No</span></td> <td colspan="1" rowspan="2" style="width: 200px; text-align: center;"><span style="font-size: 16px;">Sample Location</span></td> <td colspan="2" rowspan="1" style="width: 60px; text-align: center;"><span style="font-size: 16px;">Sampling Times</span></td> <td colspan="1" rowspan="2" style="width: 60px; text-align: center;"><span style="font-size: 16px;">Duration (mins)</span></td> <td colspan="2" rowspan="1" style="text-align: center;"><span style="font-size: 16px;">Flow Rates (l/min)</span> </td> <td colspan="1" rowspan="2" style="width: 70px; text-align: center;"><span style="font-size: 16px;">Mean<br> Flow Rate (l/min)</span> </td> <td colspan="1" rowspan="2" style="width: 70px; text-align: center;"><span style="font-size: 16px;">Sample Volume (litres)</span></td> <td colspan="1" rowspan="2" style="width: 70px; text-align: center;"><span style="font-size: 16px;">Fibres Counted</span></td> <td colspan="1" rowspan="2" style="width: 70px; text-align: center;"><span style="font-size: 16px;">Graticule Fields</span></td> <td colspan="1" rowspan="2" style="width: 70px; text-align: center;"><span style="font-size: 16px;">Limit of Detection (f/ml)</span></td> <td colspan="1" rowspan="2" style="width: 70px; text-align: center;"><span style="font-size: 16px;">Calculated Result (f/ml)</span></td> <td colspan="1" rowspan="2" style="width: 70px; text-align: center;"><span style="font-size: 16px;">Recorded Result (f/ml)</span></td> </tr> <tr> <td style="width: 40px; text-align: center;"><span style="font-size: 16px;">Start</span></td> <td style="width: 40px; text-align: center;"><span style="font-size: 16px;">Finish</span></td> <td style="width: 40px; text-align: center;"><span style="font-size: 16px;">Start</span></td> <td style="width: 40px; text-align: center;"><span style="font-size: 16px;">Finish</span></td> </tr> <tr id="Sample1"> <td><span id="SampleNumber1" style="font-size: 16px;"><%SampleNumber_1%></span></td> <td><span id="TypeofTest1" style="font-size: 16px;"><%TypeofTest_1%></span></td> <td><span id="PumpNumber1" style="font-size: 16px;"><%PumpNo_1%></span></td> <td><span id="CowlNumber1" style="font-size: 16px;"><%CowlNo_1%></span></td> <td><span id="SampleLocation1" style="font-size: 16px;"><%SampleLocation_1%></span></td> <td><span id="SampleStart1" style="font-size: 16px;"><%SampleStart_1%></span></td> <td><span id="SampleFinish1" style="font-size: 16px;"><%SampleFinish_1%></span></td> <td><span id="SampleDuration1" style="font-size: 16px;"><%SampleDuration_1%></span></td> <td><span id="FlowRateStart1" style="font-size: 16px;"><%FlowRateStart_1%></span></td> <td><span id="FlowRateFinish1" style="font-size: 16px;"><%FlowRateFinish_1%></span></td> <td><span id="FlowRateMinMean1" style="font-size: 16px;"><%FlowRatelminMean_1%></span></td> <td><span id="SampleVolumeLitres1" style="font-size: 16px;"><%SampleVolumelitres_1%></span></td> <td><span id="FibresCount1" style="font-size: 16px;"><%FibresCount_1%></span></td> <td><span id="GraticuleFields1" style="font-size: 16px;"><%GraticuleFields_1%></span></td> <td><span id="Limit1" style="font-size: 16px;"><%Limit_1%></span></td> <td><span id="CalculatedResult1" style="font-size: 16px;"><%CalculatedResult_m1%></span></td> <td><span id="ReportedResult1" style="font-size: 16px;"><%ReportedResult_1%></span></td> </tr> </tbody> So, when the if statement is met (when there is no content in the table row), the row should be hidden. If there is content, it should be shown. However the table row is never shown when there is content in it.
Please note: The <% %> are placeholders for a program I am using.
Any help into why this might be happening would be great,
Thanks.