データを含むいくつかのテーブルを含むページをまとめようとしています。ページが長くなる可能性があるため、ユーザーがヘッダーをクリックしてテーブルを折りたたむことができるようにしたいと考えています。利用可能なコンテンツが他にもあることを示すために + アイコンを使用し、折りたたみ可能であることを示すために - アイコンを使用する予定です。そこでアイコンであるiタグのクラス名を切り替える必要があります。私が言ったように、ページには同一の i タグタグを持つ複数のテーブルを含めることができるので、それをカバーする何かが必要です
HTML の例を次に示します。
<table class="table table-bordered">
<thead class="heading" id="thead">
<tr id="tr">
<th id="th" colspan="3"><i class="icon-plus"></i> Basic info</th>
</tr>
</thead>
<tbody class="content">
<tr>
<td>Registration</td>
<td>ABC 123</td>
<td> </td>
</tr>
</tbody>
</table>
<table class="table table-bordered">
<thead class="heading" id="thead">
<tr id="tr">
<th id="th" colspan="3"><i class="icon-plus"></i> More info</th>
</tr>
</thead>
<tbody class="content">
<tr>
<td>Start time</td>
<td>11:57</td>
<td> </td>
</tr>
</tbody>
</table>
そしてここにスクリプトがあります
<script type="text/javascript">
jQuery(document).ready(function() {
jQuery('.content').show();
jQuery('.heading').click(function()
{
jQuery(this).next('.content').slideToggle('0');
jQuery(this).parent().next("i").removeClass('icon-plus').addClass('icon-minus');
});
});
</script>
tbody の表示と非表示は正常に機能しますが、アイコンを変更できません。手がかりはありますか?