If your element exposes class A
from the start, you can write:
$(element).toggleClass("A B");
This will remove class A
and add class B
. If you do that again, it will remove class B
and reinstate class A
.
If you want to match the elements that expose either class, you can use a multiple class selector and write:
$(".A, .B").toggleClass("A B");
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…