JavaScript & jQuery and the use of periods

后端 未结 2 497
刺人心
刺人心 2021-01-27 15:45

I am confused when to use the period before the class names when referencing them. In this example why does the first use of the \'active-slide\' class use a period beforehand w

相关标签:
2条回答
  • 2021-01-27 16:19

    The . character is a selector. It allows you to select ALL DOM elements with that ('active-slide') class.

    The jQuery syntax $('') uses selectors to return jQuery wrapped elements.

    When you are adding/removing classes, you are not using a selector. You are literally removing a classname which is actually 'active-slide' (no .)

    0 讨论(0)
  • 2021-01-27 16:19

    $('.active-slide') is using jQuery's element selector. (add|remove)Class('active-slide'); is modifying the element.

    0 讨论(0)
提交回复
热议问题