Running an if else statement which changes the text on the button when it is clicked

Running an if else statement which changes the text on the button when it is clicked

Hello, I am developing a dropdown box which is open and closed with a button and I would like the button to change the text from open to shut when it is clicked. I have written the code to do so but the problem is that the code doesn't start executing until the second click which causes the text to be the opposite of what i want it to be. Here is the code I have so far. You can also check out it in action at  https://googledrive.com/host/0B0ATHPRjoZ2ZWFhxaDJvNHN4blU/ (For some reason Google Drive says it it is an unverified script so you may need to click allow)

Thanks in advance

  1.     <div id="dropdown_button">
  2.     Open
  3.     </div>


  4. $('#dropdown_button').click(function(){
  5.   if ($(this).text() == "Open") 
  6.  
  7.       $(this).text("Close"); 
  8.  
  9.   else 
  10.  
  11.     $(this).text("Open"); 
  12.   }; 
  13. });