【JavaScript】HTMLCollectionsでArray.prototype.forEach()などを使用する
備忘録がてら。 ブラウザ上で[document.getElementsByClassName()]等を実行した場合に返却される[HTMLCollections]はArrayのような動きをするが、最低限の機能しか備わっていない。 もし[Array.prototype.forEach()]等を実行したいのであれば、[Array.prototype.forEach.call()]を利用すると実行可能。 ※ Indexed Collectionという規格に沿っていれば利用できるみたい 例:demo1.js Array.prototype.forEach.call(document.getElement…
2022/01/14 00:00