[英]Better way for selecting table row?
我有一個以下(簡化)表結構:
<table class="form-table">
<tbody>
<tr>
<tr><--Need to select and add class on this guy based on h3 class "check"-->
<th scope="row">
<h3 class="check">Default Checbox:</h3>
</th>
<td>
</tr>
</tbody>
</table>
所以我想在h3類“check”上面選擇“table row”。 表是動態生成的,所以我不能只使用:eq()
:gt()
或:lt()
。
要選擇這個人,我使用此代碼:
$('tbody tr').find('h3.check').parent().addClass('cool');
$('.cool').parent().addClass('until');
但問題是,我給了一個不必要的課程“酷”,以便做出選擇。
<table class="form-table">
<tbody>
<tr>
<tr>
<tr class="until"><--Class successfully added but..-->
<th class="cool" scope="row"><--An extra Class in order to select "table row"-->
<h3 class="check">Default Checbox:</h3>
</th>
<td>
</tr>
</tbody>
</table>
有沒有更好的方法(不添加不必要的類)?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.