**jsで空のimgタグをつくってそこに画像を貼りたいです。
htmlで簡単にできますが、画像の数を増やしたいのとJSの勉強中なのでjsでそれを実現したいです。
よろしくお願いいたします。
**
コード javaScript
<style> body{ display:flex; flex-wrap:wrap; } .box{ width:100px; height:100px; background: skyblue; cursor:pointer; transition:0.8s; margin: 0 8px 8px 0; text-align:center; line-height:100px; } .circle{ background:pink; border-radius:50%; transform:rotate(360deg); } </style> <script> 'use strict'; for(let i=0;i<100;i++){ const img= document.createElement('img'); img.classList.add('https://www.kobegakuin.ac.jp/img/index/4.jpg'); img.textContent=i; img.addEventListener('click',function(){ img.classList.toggle('circle'); }); document.body.appendChild(img); } </script> </body> </html>
回答2件
あなたの回答
tips
プレビュー