Hi,
I have created a toggle function which reveals a container when clicked, but I would also like to hide the button itself when the text is revealed (the function works fine for the container part, but I am unable to implement the button hiding in the same function as yet).
I tried to do this in a few different ways:
-
Adding a second piece of code to be executed if the condition in the ‘if statement’ is true
-
Adding a second piece of code to be executed if the condition in the ‘IF statement’ is true AND including the visibility status of the button in the IF statement as well (as a second condition).
-
Creating a second toggle functions which deals with the button hiding on its own.
I have not been able to get this to work yet. Does anyone have any ideas please?
HTML for Button:
<button class = "james_joyce_button" id = 'james_joyce_button' onclick = "toggle2()" >James Joyce</button>
CSS for container and button:
.james_joyce_container {
display: none;
border-radius: 30px;
height: fit-content;
}
.james_joyce_button {
margin-left: 50px;
display: block;
}
Script:
let jjContainer = document.getElementById(
"james_joyce_container"
);
let jjButton = document.getElementById("james_joyce_button");
function toggle2() {
if (jjContainer.style.display === "none") {
jjContainer.style.display = "block"&& jjButton.style.display = "none";
} else {
jjContainer.style.display = "none";
}