2
2

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.

getElementsBy vs querySelector

Last updated at Posted at 2023-06-29

はじめに

初カキコ…ども…

俺みたいな1年目でQiita書いてる野郎、他に、いますかっていねーか、はは


前置きはさておき、
JS初心者で学習中に誰もが思うのが
getElementsByとquerySelectorAllどう使い分けるんだよってハナシ。
適当にまとめました。

結論querySelectorでほぼ良さげです

getElementsBy

  • DOM取得処理が~数倍速い
  • タグネームやクラスネーム指定
  • HTML Collection(1つでも[0]など指定必要、動的)

querySelector

  • 処理が比較的重い
  • CSSセレクター使える(擬似クラス使える)
  • Node List(静的、forEachメソッド使える)

おわりに

練習投稿なので補足などあればなんなりとm(_ _)m

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?