So können Sie CSS-Klassen in jQuery dynamisch hinzufügen / entfernen
jQuery enthältaddClass() undremoveClass(), um CSS-Klassen dynamisch hinzuzufügen oder zu entfernen. Zum Beispiel,
-
$(‘#para1’).addClass(‘highlight’); – Add a “highlight’ css class to elements that contain id of “para1”.
-
$(‘#para1’).removeClass(‘highlight’); – Remove a “highlight’ css class from elements that contain id of “para1”.
Beispiel
jQuery add / remove css class example
This is paragraph 1
This is paragraph 2
This is paragraph 3
This is paragraph 4