2017-04-14 7 views
0

(選択したヘッダーの色が変更されるのと同じように)現在選択されているテーブルヘッダーのみを対象にすることができます。クリックで?現在選択されているテーブルヘッダーの矢印のみを切り替えます

<table class="container cf"> 
    <thead class="cf"> 
    <tr> 
     <th class="numeric">amount <i class="glyphicon glyphicon-triangle-bottom"></i></th> 
     <th class="numeric">case <i class="glyphicon glyphicon-triangle-bottom"></i></th> 
     <th class="numeric">field 3 <i class="glyphicon glyphicon-triangle-bottom"></i></th> 
     <th class="numeric">field 4 <i class="glyphicon glyphicon-triangle-bottom"></i></th> 
     <th class="numeric">location <i class="glyphicon glyphicon-triangle-bottom"></i></th> 
     <th class="numeric">date <i class="glyphicon glyphicon-triangle-bottom"></i></th> 
    </tr> 
    </thead> 
    <tbody class="verdicts"> 
    <tr> 
     <td data-title="amount" class="amount">8,570,000.00<span class="result"></span></td> 
     <td data-title="case">title</td> 
     <td data-title="practice area">area</td> 
     <td data-title="user">Bob jones</td> 
     <td data-title="location">Orlando, FL</td> 
     <td data-title="date">Mar 6, 2017</td> 
    </tr> 
    <tr> 
     <td data-title="amount" class="amount">$447,115<span class="result"></span></td> 
     <td data-title="case">Another title</td> 
     <td data-title="practice area">area</td> 
     <td data-title="user">Joe Smith</td> 
     <td data-title="location">Orlando, FL</td> 
     <td data-title="date">Mar 6, 2017</td> 
    </tr> 
    </tbody> 
</table> 

jQueryの

$(".numeric").click(function() { 
    $(".numeric").removeClass('numeric-active'); 
    $(this).toggleClass("numeric-active"); 
    $(".glyphicon-triangle-bottom").toggleClass("rotate"); 
}); 

JSFIDDLE:LINK

答えて

0

ここでは、次のコード

$(".numeric").click(function() { 
    $(".numeric").removeClass('numeric-active'); 
    $(this).toggleClass("numeric-active"); 
    $(this).find('i').toggleClass("rotate"); 
}); 

を試してみてください作業jsfiddleです:https://jsfiddle.net/mrdag8bk/8/

0

イベントが上のトリガされたことを要素のコンテキスト内であなたの要素を探す:

$(".glyphicon-triangle-bottom", this).toggleClass("rotate"); 

または

$(this).find(".glyphicon-triangle-bottom").toggleClass("rotate"); 

JSFiddle

+0

問題は赤色が除去されなければならないということです前から他のヘッダーがクリックされたときに、賢くクリックされたヘッダー。 – Matt

+0

@Mattそれは私が見ることができる行動です。 – George

+0

これは正しいことですが、他の解決法と同じことをしています::: before擬似クラスを単語に適用するので、トグル時に単語の左に表示されるボックスがあります。 – Matt

0
$(".numeric").click(function() { 
    $(".numeric").removeClass('numeric-active'); 
    $(this).toggleClass("numeric-active"); 
    $(this).children("i").toggleClass("rotate"); 
}); 

https://jsfiddle.net/mrdag8bk/7/

+0

これはちょうど私が探していたものです。ただし、ヘッダーの左側に小さなボックスが表示されているのを除いて、これは表示されていないグリフコンです。クリックするだけで矢印を回転させ、:: before擬似クラスを適用するのではありません。 – Matt

関連する問題