- 1つをクリックすると色が変わる。
- 別のボタンをクリックするとそれの色が変わり、最初にクリックしたボタンの色は初期の色に戻る
- ホバーではなくクリックしたら色は次のボタンがクリックされるまでそのまま
のような実装をしたいです。
例
何もしていない状態
ボタン ボタン ボタン ボタン ボタン
↓
クリック
ボタン ボタン ボタン ボタン ボタン
↓
別のボタンをクリック
ボタン ボタン ボタン ボタン ボタン
↓
さらに別のボタン
ボタン ボタン ボタン ボタン ボタン
のような感じです。
現在のソースです。
html
1<tr class="is-sorter" id="aaa"> 2 <th> 3 <a href="?r1=1#aaa" class="is-desc">A 降順</a> 4 <a href="?r1=0#aaa" class="is-asc">A 昇順</a> 5 </th> 6 <th> 7 <a href="?r2=1#aaa" class="is-desc">B 降順</a> 8 <a href="?r2=0#aaa" class="is-asc">B 昇順</a> 9 </th> 10 <th> 11 <a href="?r3=1#aaa" class="is-desc">C 降順</a> 12 <a href="?r3=0#aaa" class="is-asc">C 昇順</a> 13 </th> 14 <th> 15 <a href="?r4=1#aaa" class="is-desc">D 降順</a> 16 <a href="?r4=0#aaa" class="is-asc">D 昇順</a> 17 </th> 18```ご教授のほどよろしくお願いいたします。 19 20追記 21回答者様のコードをお借りしてます。 22```js 23$(function(){ 24 var sortkey=location.search+location.hash; 25 $('a[href="'+sortkey+'"]').css({"background-Color":"red"}); 26});
この記述の仕方でcssの部分をaddClassでクラスの追加は可能でしょうか?
回答2件
あなたの回答
tips
プレビュー