0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

JavaScriptで出てくる「this」、「children」について

Posted at

本題

早速ですが
「this」と、「children」の違いを解説していきます。

  • 「this」はイベントが発生した要素のみを変化させます。
  • 「children」はHTML要素直下のすべての子要素を取得できます。

例えばthisを使うと正方形にクリックした時、その正方形のみslideUPして消えていく機能を作れます。

対して、childrenを使うとリスト(ul要素)の子要素であるli内の文字列がすべて
黒色から赤色に変化する機能を作れます。
thisやchildrenを使うと変更したい要素を簡単に指定できて便利です。

要は、

thisは個別でイベント発生
childrenは子要素をまとめてイベント発生

みたいなイメージですかね。知らんけど。

まとめ

本日は「this」と、「children」の違いについて解説していきました。
javascriptは奥が深いですね。
それでは、また次回もお願いします!

0
0
1

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?