document.addEventListener("DOMContentLoaded", function () { const pic = document.getElementById("profilePic"); const menu = document.getElementById("profileMenu"); if (!pic) { console.log("profilePic NOT FOUND"); return; } pic.addEventListener("click", function (e) { e.stopPropagation(); // stops auto-close menu.style.display = (menu.style.display === "block") ? "none" : "block"; }); document.addEventListener("click", function (e) { if (!menu.contains(e.target)) { menu.style.display = "none"; } }); });

ok, so I copied the above code from chatGPT. I am trying to make a social media app using PHP. What I want to happen is, when I click on the profile picture on the leftmost corner, a menu should pop up with two options - 1)see imagae 2)change image
Now, The menu automatically appears every time I reload the page. I dont know why that is happening. Can someone help me with that?
enter image description here

This is what shows up when I reload the page. And when I click on it again, it looks like this
I would appreciate your help.

Saad Nadaf's user avatar

New contributor

Saad Nadaf is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.