I have a number of tables similar to the following html code:
<table id="film"><tr> <th class="1">//HEAD CONTENT 1//</th> </tr> <tr> <td class="1">//BODY CONTENT 1//</td> </tr></table> <table id="film"><tr> <th class="2">//HEAD CONTENT 2//</th> </tr> <tr> <td class="2">//BODY CONTENT 2//</td> </tr></table>
I want the tables to expand individually when the corresponding head ( <th> ) is pressed. In addition, tables should start unchanged. I am using the following jQuery script:
$(document).ready(function(){ $('#film td').hide(); }); $(document).ready(function(){ var n1 = 0; $('#film th.1').click(function(){ if(n1 == 0){ $('#film td.1').show(); n1 = 1; }else{ $('#film td.1').hide(); n1 = 0;} }); var n2 = 0; $('#film th.2').click(function(){ if(n2 == 0){ $('#film td.2').show(); n2 = 1; }else{ $('#film td.2').hide(); n2 = 0;} }); });
However, when I execute only the top table, you can show / hide not the second. Can anyone see where I'm wrong?
source share