- Products -


Software


NEWS


Special



- Knowledge -


Category × Tag



- Like -

公開
作成日:2021/11/21
更新日:2021/11/21

【Javascript】querySelectorAllで取得した要素をループで処理する方法

・jQueryでは次のように書く。「$(~).each(function(){処理});」

・これをjs標準の機能で行う場合は次のように書く。「document.querySelectorAll(~).forEach(function(){});」

・lengthを見て単純なforで回すというやり方もできるが、forEachを使える場合はこちらを使いたい。

使い方



document.querySelectorAll(".tags a").forEach(item => {
  console.log(item.innerText);
});


参考


https://thr3a.hatenablog.com/entry/20190304/1551701684


Category



Tag




関連記事


{{tmp.name}}

{{article.category}} {{article.title}}