Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

select multiple elements by ID in one line

Tags:

javascript

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("jobDescription").style.display = "block";
    document.getElementById("updateButton").style.display = "block";
    document.getElementById("equipmentList").style.display = "block";
    document.getElementById("jobDesc").style.display = "block";
    document.getElementById("equipRan").style.display = "block";
}

I would like to have just one line that will unhide all of the elements if its possible I have tried document.getElementById("jobDescription" + "updateButton" + etc...).style.display = "block"; but it does not work. I am new to JavaScript.

like image 960
Yamaha32088 Avatar asked Dec 06 '22 10:12

Yamaha32088


1 Answers

Give all your required elements a class and select them through getElementsByClassName(..).

(and maybe use jQuery to do the same thing with much less pain)

like image 88
Jack Avatar answered Dec 25 '22 04:12

Jack