1
1

More than 1 year has passed since last update.

【jQuery】hoverでclassを付け外し

Posted at

自分用メモ書き
ホバー時に複数の要素を動かしたい時に便利

index.html
<a class="link1" href="URL">リンク1</a>
<a class="link2" href="URL">リンク2</a>
link.js
//================================
//  ! ホバーでクラスの付け外し
//================================
$(function(){
    $('.link1,.link2').hover(function(){ //hoverしたら
        $(this).addClass('active'); //「active」クラスを加える
    },function(){
        $(this).removeClass('active'); //「active」クラスを外す
    });
});
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1