使用jQuery获取元素的类列表
问题: Is there a way in jQuery to loop through or assign to an array all of the classes that are assigned to an element? jQuery中是否有一种方法可以循环或将分配给元素的所有类分配给数组? ex. 例如 <div class="Lorem ipsum dolor_spec sit amet">Hello World!</div> I will be looking for a "special" class as in "dolor_spec" above. 我将在上面的“ dolor_spec”中寻找“特殊”类。 I know that I could use hasClass() but the actual class name may not necessarily be known at the time. 我知道我可以使用hasClass(),但是实际的类名可能在那时不一定是已知的。 解决方案: 参考一: https://stackoom.com/question/59Gw/使用jQuery获取元素的类列表 参考二: https://oldbug.net/q/59Gw/Get-class-list-for-element-with-jQuery 来源: