title: If element with ID has as class
body: <p>What I have now is</p>
  
  <pre><code>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";
  }
  }
  </code></pre>
  
  <p>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. </p>
  
  <p>So I tried this code:</p>
  
  <pre><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";
  }
  </code></pre>
  
  <p>The   </p>
  
  <pre><code>if (getElementById("game_" + variable).hasClass("current_nav")) {} else {
  </code></pre>
  
  <p>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.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I got the correct answer: from wroniasty</p>
  
  <pre><code>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";
  }
  }
  </code></pre>