addclass(class)为每个匹配的元素添加指定的类名。
adds the specified class(es) to each of the set of matched elements.
返回值jquery
参数class (string) : 一个或多个要添加到元素中的css类名,请用空格分开
示例为匹配的元素加上 'selected' 类
html 代码:
hello
jquery 代码:
$(p).addclass(selected);
结果:
[ hello
]
为匹配的元素加上 selected highlight 类
html 代码:
hello
jquery 代码:
$(p).addclass(selected highlight);
结果:
[ hello
]
------------------------------------------------------------------------------------------------------------------------------
removeclass(class)从所有匹配的元素中删除全部或者指定的类。
removes all or the specified class(es) from the set of matched elements.
返回值jquery
参数class (string) : (可选) 一个或多个要删除的css类名,请用空格分开
示例从匹配的元素中删除 'selected' 类
html 代码:
hello
jquery 代码:
$(p).removeclass(selected);
结果:
[ hello
]
删除匹配元素的所有类
html 代码:
hello
jquery 代码:
$(p).removeclass();
结果:
[ hello
]
------------------------------------------------------------------------------------------------------------------------------
toggleclass(class)如果存在(不存在)就删除(添加)一个类。
adds the specified class if it is not present, removes the specified class if it is present.
返回值jquery
参数class (string) :css类名
示例为匹配的元素切换 'selected' 类
html 代码:
hello
hello again
jquery 代码:
$(p).toggleclass(selected);
结果:
[ hello
, hello again
]