innerHTML with getElementByClassName doesn't work

前端 未结 6 1499
旧时难觅i
旧时难觅i 2020-12-07 06:36

This one works:



        
6条回答
  •  时光说笑
    2020-12-07 06:53

    document.getElementByClassName('whatever') returns array of html object elements inside the document,

    so you need

    var ele = document.getElementsByClassName('textbox');
    
    ele[0].innerHTML = "Whatever text" ;
    

    If you want to set inner html to all the elements of this class you can use

    for(var i=0;i

提交回复
热议问题