I need to dynamically hide some text and show specific labels upon clicking a button. How can I achieve this?
<body>
<div id="middle">
<div id="left">
</div >
<div id="m">
Name: <input type="text" name="y1"><br />
Family: <input type="text" name="y1"><br />
Phone: <input type="text" name="y1"><br />
<label style="display: none " name="y2" >A </label>
<label style="display: none " name="y2" >B </label>
<label style="display: none " name="y2" >C </label>
<button onclick="myFunction()">Hide elements</button>
<script>
function myFunction() {
var x = document.getElementsByName("y1");
for (var i = 0; i < x.length; i++) {
x[i].style.display = "none";
}
var x = document.getElementsByName("y2");
for (var i = 0; i < x.length; i++) {
x[i].style.display = "visible !important";
}
}
</script>
</div>
</body>