1

I'm fairly new to JavaScript so I don't quite understand why I am getting a syntax error on 'else'. Any advise?

<script language="javascript">
 $(document).ready(function() {
      $('#toggleButton').click(function() {
           if ($('#toggleSection').css("opacity") == 0); {  
                $('#toggleSection').fadeIn("slow");
           } 
           else {
                $('#toggleSection').fadeOut("slow");
           }
           return false;
      });
 });
 </script>
1
  • 4
    For basic syntax errors, just run your code through jslint.com. Commented Oct 18, 2011 at 0:44

3 Answers 3

3
if ($('#toggleSection').css("opacity") == 0);

Remove that semicolon on the end..

Sign up to request clarification or add additional context in comments.

Comments

2
if ($('#toggleSection').css("opacity") == 0); {

Hi, I think your ; is wrong here. Good luck!

Comments

1

You have an extra ; after the if

This is parsed as an if around an empty statement (which is useless), followed by an ordinary { ... } block, followed by a dangling else.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.