[jQuery syntax] > class with a dot or not?


Hello all,

I just begun writing javascript. It looks promising.

my question:

  • i have a CSS class called 'article'
  • i also have another CSS class called 'current'

in jQuery syntax, when i want to select the class 'article' i write:

When i want to remove the class 'current' from the class 'article'

it is wrong to write:

but instead it is correct to write:

what is the logic of omitting the '.' (dot) ??


Hi Mhtcka,

You know how to use CSS selectors, right?


When you select something (say, $('.article')), you need that dot (.) to distinguish it from being a tag or id selector. But with add/remove/toggleClass(), the computer knows it's dealing with a class, so no dot is necessary.

I hope this helps :slightly_smiling:


ok understood thanx!