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


#1

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:
$('.article')

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

it is wrong to write:
$('.article').removeClass('.current');

but instead it is correct to write:
$('.article').removeClass('current');

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


#2

Hi Mhtcka,

You know how to use CSS selectors, right?

tag
.class
#id

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:


#3

ok understood thanx!