如何獲得作爲jQuery對象的#<HTMLDivElement>
?對象#<HTMLDivElement>作爲jQuery對象
我需要做以下幾點:我有一個div的列表與類的內容。所以我遍歷它,直到我找到了一個與附加類:「測試」
這裏是我的代碼:
$.each($(".contents"), function(key, value) {
if (value.hasClass("test"))
{
alert("got it");
}
});
,我發現了異常:Uncaught TypeError: Object #<HTMLDivElement> has no method 'hasClass'
只要它傳遞給[jQuery的構造](http://api.jquery.com/jQuery/#jQuery-element)。 – Bergi 2013-05-06 09:50:53
你爲什麼不使用像'$(「。contents.test」)這樣的選擇器?each(alert.bind(window,「got it」))'?或'$(「。contents」)。filter(「。test」)'? – Bergi 2013-05-06 09:51:20