title: if/else statement in a function: using onclick as a switch
body: <p>I have looked for solutions to this on google for what seems like an eternity, but I can't seem to formulate my search correctly, or nobody has posted the code I'm looking for earlier.</p>
  
  <p>I am currently trying to make a function that will modify one or several margins of a div element. I want to use an if/else statement within the function, so that the onclick event will switch between the two conditions. This is what I have been working on so far;</p>
  
  <pre><code>function facebookToggle()
  {
      if($('#facebooktab').style.margin-left == "-250px";)
      {
          document.getElementById("facebooktab").style.marginLeft="0px";
      }
      else
      {
          document.getElementById("facebooktab").style.marginLeft="-250px";
      }
  }
  </code></pre>
  
  <p>I have tried twisting it around a little, like switching between "marginLeft" and "margin-left", to see if I was just using the wrong terms.. I'm starting to wonder if it might not be possible to combine jQuery and regular javascript? I don't know.. It's all just guesses on my part at this point.</p>
  
  <p>Anyway, I have a div, which is now positioned (fixed) so almost all of it is hidden outside the borders of the browser. I want the margin to change onclick so that it will be fully shown on the page. And when it is shown, I want to be able to hide it again by clicking it.</p>
  
  <p>I might be approaching this in the wrong way, but I really hope someone can help me out, or even tell me another way to get the same results. Thank you for any help you can give me.</p>
  
  <p>You can see it in action at: <a href="http://www.torucon.no/test/" rel="nofollow">http://www.torucon.no/test/</a></p>
  
  <p>(EDIT: By the way, I am a complete javascript novice, I have no experience with javascript prior to this experiment. Please don't be too harsh, as I am aware I probably made some really stupid mistakes in this short code.)</p>
  
  <p>Fixed problem:</p>
  
  <pre><code>function facebookToggle() {
  var fb = $('#facebooktab'); // save reference to element
  if( fb.css('margin-left') === '-250px' ) {
      fb.css('margin-left', '0px');
  } else {
      fb.css('margin-left', '-250px');
  }
  }
  </code></pre>