What I have now is
function setMenuCurrentTo(variable) { document.getElementById("game_" + variable).style.display = "block"; var elems = document.getElementsByClassName("current_nav"); for (var i=elems.length; i--;) { elems[i].style.display = "none"; elems[i].className = 'none'; } document.getElementById("game_" + variable).className="current_nav"; } } So when I click a tag with a specific element(variable) it adds a content and "hides" another one. But there is a bug that when I click twice in the same button, the content dissapears and I don't have anymore content.
So I tried this code:
function setMenuCurrentTo(variable) { document.getElementById("game_" + variable).style.display = "block"; if (getElementById("game_" + variable).hasClass("current_nav")) { } else { var elems = document.getElementsByClassName("current_nav"); for (var i=elems.length; i--;) { elems[i].style.display = "none"; elems[i].className = 'none'; } document.getElementById("game_" + variable).className="current_nav"; } The
if (getElementById("game_" + variable).hasClass("current_nav")) {} else { Make the code don't work, the content appears but no other "hides". What is the problem in my code? Thank you, I'm very new at JavaScript, I got yesterday help for the original code. Thank you again.
EDIT:
I got the correct answer: from wroniasty
function setMenuCurrentTo(variable) { document.getElementById("game_" + variable).style.display = "block"; if (jQuery('#game_' + variable).hasClass('current_nav')) { } else { var elems = document.getElementsByClassName("current_nav"); for (var i=elems.length; i--;) { elems[i].style.display = "none"; elems[i].className = 'none'; } document.getElementById("game_" + variable).className="current_nav"; } }