Is this an acceptable way to call a div with javascript?

html

<button id="openImg">Click here to open</button>
	<button id="closeImg">Click here to close</button>
	<div id="myPics">
		<img src="ga1.jpg">
	<img src="ga2.jpg">
	</div>

css

#myPics {
	display: none;
}

js

var openImg = document.getElementById('openImg');
var closeImg = document.getElementById('closeImg');
openImg.onclick = function() {
    myPics.style.display = "block";
}

closeImg.onclick = function() {
    myPics.style.display = "none";
}

I just want to get the images when i click the button to open which is what my code is doing already but wanted to know if this is the right way or at least acceptable

so when could be right to style directly using the id or class selector?

Class selector is fine. The id selector is rarely used normally.

perfect thanks alot im new with javascript thanks again