select multiple elements by ID in one line

前端 未结 5 2109
自闭症患者
自闭症患者 2021-01-06 08:56

I would like to know if there is a better/cleaner way to accomplish what I have in the code below.

var updateJob = function(){
    document.getElementById(\         


        
5条回答
  •  天涯浪人
    2021-01-06 09:56

    You could use a loop:

    var elements = ['jobDescription', 'updateButton', 'equipmentList', 'jobDesc', 'equipRan'];
    
    for(i = 0; i < elements.length; i++) {
       document.getElementById(elements[i]).style.display = "block";
    }
    

提交回复
热议问题