addClass


#1

form the above course , why is it that in $('.article').click(function(){
$(this).addClass('.current');
});
there is a dot symbol (.) in the parentheses with current class
but in $(document).keypress(function(event){
else if(event.which === 110){
nextArticle.addClass('current');
}
});

this is no dot symbol (.) infront of the class name current??


#2

Hi Owusua,

addClass(), removeClass(), and toggleClass() never take a dot (.) before the class name. The reason for that is because the dot separates a class selector from an id or tag selectors (take the HTML & CSS course for more on those). With add/remove/toggleClass() though, the computer knows it's getting a class as an input, so the dot isn't needed.

Does that help you? :)


#3

yeah but why does it show in the first instance


#4

I'm not sure. It shouldn't. Would you mind posting a link to the exercise you're on?


#5

https://www.codecademy.com/en/courses/web-beginner-en-4hxyb/0/9?content_from=make-an-interactive-website%3Ajquery-events


#6

The code there is based off of your code from the previous exercises. So if it has addClass('.current');, it's probably because that's what you typed in an earlier exercise.


#7

okay, thank you for your help