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
- <div id="dropdown_button">
- Open
- </div>
- $('#dropdown_button').click(function(){
- if ($(this).text() == "Open")
- {
- $(this).text("Close");
- }
- else
- {
- $(this).text("Open");
- };
- });