<!DOCTYPE html>
<html>
<head>
<title>
Hide or show HTML elements using
visibility property in JavaScript
</title>
<style>
.container {
height: 80px;
width: 250px;
border: 2px solid black;
background-color: green;
color: white;
</style>
</head>
<body>
<center>
<div class="container">
<h1>Number of Child</h1>
</div>
<p class="container2">
Click the buttons to show
or hide the green box
</p>
<input type="radio" id="female" name="gender" value="female" onclick="showElement()"
checked>
<label for="female">Female</label>
<label for="male">Male</label>
<input type="radio" id="male" name="gender" value="male" onclick="hideElement()">
</center>
<script type="text/javascript">
function showElement() {
element = document.querySelector(".container");
element = document.querySelector(".container2");
element.style.visibility = 'visible';
}
function hideElement() {
element = document.querySelector(".container");
element = document.querySelector(".container2");
element.style.visibility = 'hidden';
}
</script>
</body>
</html>
Okay so here's the simple code, I want to target 2 elements, which are : ".container"and ".container2"
but the method document.querySelector only choose one, how can I fix this ?
Link to the code : https://jsfiddle.net/7cgmq0tx/
querySelectorAll()?