Help needed


#1

given the following code:
var main = function (){
$('dropdown-toggle').click(function(){
$('dropdown-menu').toggle();
});

$('.arrow-next').click(function(){

    var currentSlide = $('.active-slide');
    var nextSlide = currentSlide.next();
    currentSlide.fadeOut(600).removeClass('active-slide');
    nextSlide.fadeIn(600).addClass('active-slide');

});

};

$(document).ready(main);

why does the removeClass('active-slide'); work without using '.active-slide' I taught the dot is needed to call class in jquery but here and also using the addClass('active-slide'), it is used without the dot. And that was the correct syntax. Please help me understand y. Thanks


#2

Hey Lawreneagles,

When we select something using jQuery, we could select:

$('#example') // an id
$('.example') // a class
$('example') // or a tag

So something is needed to distinguish between each of those, especially in cases where you might have the same #id and .class name for some reason. With add/removeClass() however, jQuery knows we're dealing with a .class, so no distinction is necessary.

I hope this helps you!


#3

Thank you for this answer. I had the same question. You just made everything click with that simple explanation.


#4

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.