LoginSignup
1
0

More than 3 years have passed since last update.

jQueryのcssをJavaScriptで書き換えたらこうなる一例

Last updated at Posted at 2019-09-15

自分自身の基礎力向上のために、jQueryで作ったコードがJavaScriptで書いたらどのようになるか書いてみています。もし、他にも方法がありましたら、ご教示いただけると嬉しいです。

結果

ダウンロード.gif

jQueryのhover

jQuery

 $('button').hover(function () {
 //マウスカーソルが重なった時の処理
 $('button').css('background-color', '#f00');
 },
 function () {
 //マウスカーソルが離れた時の処理
   $('button').css('background-color', 'yellowgreen');
 })

JavaScriptのみ

 const target = document.getElementById('target');
 target.addEventListener('mouseenter', () => {
   target.style.backgroundColor = '#f00';
 }, false);

 target.addEventListener('mouseleave', () => {
   target.style.backgroundColor = 'yellowgreen';
 }, false);

HTMLElement.style

1
0
2

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
0