My website has the code snippet below:
let txt_com = document.querySelector(".text_user");
let num_com_user = document.querySelector(".massage_for_user");
txt_com.addEventListener("click", function() {
if (this.classList.contains("num_com_user")) {
this.classList = "num_com_user";
num_com_user.style.display = "none";
} else {
this.classList = "num_com_user";
num_com_user.style.display = "block";
}
return;
})
<div class="box_main">
<div class="box-txt">
<span class="text_user">click</span>
</div>
<span class="massage_for_user">No text found!</span>
</div>
The issue I am facing is that this code works only once and requires a page refresh for it to work again. What I actually want is for the menu to toggle open/close every time I click on the post.