document.getElementById can't select more than one element

前端 未结 4 1214
暗喜
暗喜 2021-01-29 14:01

I\'m working on loading. I have div #loading which is visible. And more divs #message which are hidden. I have js function.

function lo         


        
4条回答
  •  孤独总比滥情好
    2021-01-29 14:13

    You cannot have same id twice in a document in order to select multiple elements group them by same Class rather than by id and then use the following to select them all.

    document.querySelectorAll(".ClassName")
    

    Or

    document.getElementsByClassName(".ClassName");
    

    Note that both methods returns a collection of all elements in the document with the specified class name, as a NodeList object.

提交回复
热议问题