Help us understand the problem. What is going on with this article?

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

自分自身の基礎力向上のために、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

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away