This forum is now read-only. Please use our new forums! Go to forums
Theoretical question about when to use .classes and classes
I’ve not understood the difference on when use a “.class” and when a “class” (with or without the initial dots). I think I’ve get it that one is from CSS and the other from HTML For example in the code:
var main = function () {
$('.dropdown-toggle').click(function() {
$('.dropdown-menu').toggle();
});
$('.arrow-next').click(function() {
var currentSlide = $('.active-slide');
var nextSlide = currentSlide.next();
var currentDot = $('.active-dot');
var nextDot = currentDot.next();
if (nextSlide.length == 0) {
nextSlide = $('.slide').first();
};
currentSlide.fadeOut(600).removeClass('active-slide');
nextSlide.fadeIn(600).addClass('active-slide');
currentDot.removeClass('active-dot');
nextDot.addClass('active-dot');
});
};
$(document).ready(main);
Why at the beginning of the .click function it’s used ‘.active-slide’ and ‘.active-dot’, but at the end it’s used ‘active-slide’ and ‘active-dot’ (without the dots .)? Why can’t use the same (both with or without the dots) in the whole function? The code is correct and functioning, I just don’t understand the theory behind this, I hope that someone can explain me… Thank a lot!
Answer 54aab1f59113cba02c009de2
If you use $( ), you are using the so-called jQuery-Selector, which selects HTML-Elements, by using the CSS-syntax, you therefor have a http://api.jquery.com/class-selector/ http://api.jquery.com/element-selector/
With the addClass()-, removeClass()- and toggleClass()-Methods you are using the class-name as an argument so no pre-pending dot, just the -class-name-
Popular free courses
- Free Course
Learn SQL
In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language.Beginner friendly,4 LessonsLanguage Fluency - Free Course
Learn JavaScript
Learn how to use JavaScript — a powerful and flexible programming language for adding website interactivity.Beginner friendly,11 LessonsLanguage Fluency - Free Course
Learn HTML
Start at the beginning by learning HTML basics — an important foundation for building and editing web pages.Beginner friendly,6 LessonsLanguage Fluency
1 comments
Alright, now I’ve get it. Thank you very much!