2012-04-26 4 views
1

"tableClass"クラスの表にスタイルを割り当てる必要があります。私は以下のマークアップを持っています。 datarowclassからjqueryで親に行く最速の方法

<table border="0" cellpadding="0" cellspacing="0" class="tableClass"> 
    <tr> 
    <td> 
    <table border="0" cellpadding="0" cellspacing="0" class="tableClass"> <-- Need to add a style here 
     <tr class="colheadrowclass"> 
     .. some markup here 
     </tr> 
     more markup 
     <tr id="dataRow" class="datarowclass"> 
     </tr> 
    </table> 
    </td> 
    </tr> 
</table> 

、私はクラスtableClassで最初のテーブルまでを横断し、それにスタイルを追加する必要があります。

これは私にとってはうまくいくが、もっと速い方法があるのだろうかと思っていた。

$(".datarowclass").parents("table").eq(0).css("hieght", "500px"); 

答えて

1

次はあなたを助ける必要があります。

$('.datarowclass').closest('table.tableClass').css("height", "500px"); 

それはあなたが言及した正確に何を行いますdatarowclassクラスと

  1. 選択要素。
  2. それ(ポイント1で見つかった要素が) tableClassクラスに最も近い tableまで検索から
  3. 、注意 2.

ポイントで見つかった要素の

  • 変更スタイル:あなたが持っていましたtypo ""のプロパティ(「hieght」というスペルが間違っています)。

  • 0

    .closest()を使用して、.eq(0)を削除してください。

    $(".datarowclass").closest("table").css("hieght", "500px"); 
    
    関連する問題