본문 바로가기

Programming/Javascript

버튼을 눌러 이미지 사라지기

IMG.zip
2.41MB

<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
<style>
img {
	width: 200px;
	height: 200px;
}
</style>
</head>
<body>
	<img class="img" src="./IMG/ev.png">
	<img class="img" src="./IMG/firee.png">
	<img class="img" src="./IMG/ggobugi.png">
	<img class="img" src="./IMG/leesanghaessee.png">
	<img class="img" src="./IMG/pikachu.png">
	<button id="hide">사라지기</button>

	<script type="text/javascript">
		var hide = document.getElementById('hide');
		var imgs = document.getElementsByClassName('img');

		hide.addEventListener('click', function() {
			for (var i = 0; i < imgs.length; i++) {
				imgs[i].style.display = "none";
			}
		});
	</script>
</body>
</html>