我有以下内容:
<html lang="en" class="no-js theme-light"> or
<html lang="en" class="no-js xxx yyy theme-light">
我想这样做,以便单击链接会将其更改为:
<html lang="en" class="no-js theme-dark">
<html lang="en" class="no-js xxx yyy theme-dark">
再次单击会将其更改回来。即删除 theme-dark
并添加 theme-light
。
有人可以解释一下我如何使用 jQuery
做到这一点吗?
$('#sidebar-theme-switch').click(function (e) {
???
});
最佳答案
$('#sidebar-theme-switch').click(function() {
$('html').toggleClass('theme-light theme-dark')
});
Description: Add or remove one or more classes from each element in the set of matched elements, depending on either the class's presence or the value of the switch argument.
关于jquery - 如何检测某个类的存在并添加或删除另一个类?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11290251/