Check if class already assigned before adding

后端 未结 4 1757
面向向阳花
面向向阳花 2020-12-01 05:47

In jQuery, is it recommended to check if a class is already assigned to an element before adding that class? Will it even have any effect at all?

For example:

<
4条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 06:16

    Just call addClass(). jQuery will do the check for you. If you check on your own, you are doubling the work, since jQuery will still run the check for you.

提交回复
热议问题