Possible Duplicate:
Are curly braces necessary in one line statements in JavaScript?
I am almost positive of this, but I want to make sure to avoid faulty code. In JavaScript do single if statements need curly braces?
if(foo)
bar;
Is this OK?
Yes, it works, but only up to a single line just after an ‘if’ or ‘else’ statement. If multiple lines are required to be used then curly braces are necessary.
The following will work
The following will NOT work the way you want it to work.
But if the above is corrected as in the below given way, then it works for you: