我该如何将 #<HTMLDivElement>
转换为 jQuery 对象?
我需要完成以下操作:我有一个具有 class 为 "contents" 的 div 列表。所以我迭代它,直到找到带有额外类名 "test" 的 div。
这是我的代码:
$.each( $(".contents"), function( key, value ) {
if (value.hasClass("test"))
{
alert("got it");
}
});
我遇到了一个异常:
Uncaught TypeError: Object #<HTMLDivElement> has no method 'hasClass'
。
$(".contents.test").each(alert.bind(window, "got it"))
这样的选择器呢?或者是$(".contents").filter(".test")
? - Bergi