In this bellow program i'am displaying the table rows if and only if the related checkboxes are checked. And i'm hiding table rows if and only if the related check boxes are not checked.
This is my check box definition:
<div id="cb"> <input type="checkbox" value="air india"> <input type="checkbox" value="king fisher"> <input type="checkbox" value="Go Air"> </div> Example: If i click on first check box, the table row which contains the value 'air india' will display. If i uncheck that will hide.
Here hiding is working well, but display is not working properly.It is missing inner table. Bellow is my code.
<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { function inArray(haystack, needle) { var found = false; $.each(haystack, function(i, elem) { if(elem === needle) { found = true; return false; } }); return found; } $("#cb").find('input:checkbox').click(function() { var myArray =new Array(); $("#cb").find('input:checkbox').each(function(index) { if($(this).attr("checked")==true) { myArray.push($(this).val()); } }); $('#abc tr').each(function() { var td = $('> td:nth-child(2)', this); if(!inArray(myArray, td.text())) { $(this).hide(); } else { $(this).show(); } }); }); }); </script> <table id="abc" border="1"> <tr > <td></td> <td>air india</td> <td> <table> <tr> <td>Hai</td> </tr> </table> </td> </tr> <tr> <td></td> <td>king fisher</td> <td> <table> <tr> <td>Hai</td> </tr> </table> </td> </tr> <tr> <td></td> <td>Go Air</td> <td> <table> <tr> <td>Hai</td> </tr> </table> </td> </tr> </table> <div id="cb"> <input type="checkbox" value="air india"> <input type="checkbox" value="king fisher"> <input type="checkbox" value="Go Air"> </div>