What is the correct syntax in jQuery?



I am a bit confused about the proper syntax in jQuery. The following code works with both { and ; at the end...which is correct?

$(document).ready(function() {
    $('div').hideto() {


If I put $('div').hideto(){ it works and if I use a ; instead at the end it works, which is the correct way?
Also if I put "div" or 'div' both work, which is correct, double quotes or singles.



Hi Faar23,

There's no hideto() jQuery function. I think you're supposed to be using hide(), but I'm not sure which exercise you're on.

To answer your question though, it doesn't work with the opening curly brace ({) right there. Your code will throw an error if you leave it there. Having the semi-colon (;) at the end of that line is correct.

I'd recommend you take the JavaScript course, since it'll teach you a bit more about the syntax to use :slightly_smiling:



Yes it was hide not hideTo, I mixed it up with fadeTo. I will be taking the javascript course next. But in one of the earlier exercises, the whole code didn't work without { at the end of line 2. Does there have to be a { at the end of line 2?

This is the thread where I am asking about it.



Thats only there because you opened another function, if you dont open a function on line 2 then its not needed.