Consider the set of codes I have for my three elements of ids fill2a
, show2
, choice2
:
document.getElementById("fill2a").style.display="block";
document.getElementById("show2").style.display="block";
document.getElementById("choice2").style.display="block";
Can I replace the above code snippet into something like this? (I actually don’t know the format)
style.display=block for ids='fill2a','show2','choice2';
Can I create an array and then work? Explain kindly what to do.
3
Answers
You can try creating an array of element’s id. Then iterate over them to set the style like the following way:
You could use a for… in loop to loop over an array of ID’s:
Don’t address the style of the elements directly.
Write a stylesheet using classes and descendant combinators:
Then add the class on the ancestor: