I am trying to make multiple elements appear with the click of a button using one script.
This is supposed to happen: button b1 hides p1 and button b2 hides p2.
This is my current code:
<html>
<body>
<p id="p1">Disapear 1</p>
<button id="b1" onclick="toggle(p1)">hide 1</button>
<p id="p2">Disapear 2</p>
<button id="b2" onclick="toggle(p2)">hide 2</button>
<script>
function toggle(id) {
var x = document.getElementById("id");
if (x.style.visibility === "hidden") {
x.style.visibility = "visible";
} else {
x.style.visibility = "hidden";
}
}
</script>
</body>
</html>
Is there any way to carry information with the click of a button to the function.