[jQuery 筛选-过滤] hasClass(class)

检查当前的元素是否含有某个特定的类,如果有,则返回true。

这其实就是 is(“.” + class)。

返回值
Boolean

参数
class (String) : 用于匹配的类名

示例
给包含有某个类的元素进行一个动画。

HTML 代码:<div class="protected"></div><div></div> jQuery 代码:$("div").click(function(){ if ( $(this).hasClass("protected") ) $(this) .animate({ left: -10 }) .animate({ left: 10 }) .animate({ left: -10 }) .animate({ left: 10 }) .animate({ left: 0 }); });