使用jquery获取类名

Nao*_*aor 5 jquery

在名为 $target 的变量中设置的 div 元素内,我有具有单个类的元素。我想传递抛出每个元素并获取其类名。像这样的东西:

$.each($target.children(), function(){
    //get class from 'this' - how?
});
Run Code Online (Sandbox Code Playgroud)

最好的方法是什么?

我不想使用经典的 JavaScript (.className) 来做到这一点!

Cha*_*ndu 5

使用 attr 函数。例如

$.each($target.children(), function(){
    alert($(this).attr("class"))
});
Run Code Online (Sandbox Code Playgroud)