How to add multiple divs with appendChild?

前端 未结 4 553
挽巷
挽巷 2020-12-13 18:03

I am trying to make a chessboard using javascript and creating 64 divs with it.
The problem is, that it creates only the first div.
Here is the code:



        
4条回答
  •  北海茫月
    2020-12-13 18:42

    function crt_dv(){
    dv=document.createElement('div'),document.body.appendChild(dv)
    };
    
    crt_dv(),dv.className='white';crt_dv(),dv.className='black';
    

    Also use: for(i=0;i<2;i++)

提交回复
热议问题