add class via jquery but only when not exists

前端 未结 7 955
刺人心
刺人心 2020-12-15 02:25

I would like to add a class (class=\"bbox\") to a ul-list but only if no class exists. This is what i have so far. How do I check with jquery if a class exists in the ul-tag

7条回答
  •  萌比男神i
    2020-12-15 03:10

    Just use $('.selector').addClass("myClass");.

    The jQuery add/remove class functions both check for duplicates internally, meaning that calling addClass twice only will add the class once.

提交回复
热议问题