如何使用jQuery获取div的当前类? [英] How can I get the current class of a div with jQuery?
本文介绍了如何使用jQuery获取div的当前类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用jQuery,如何获取div div1
的当前类?
Using jQuery, how can I get the current class of a div called div1
?
推荐答案
只需获取class属性:
Just get the class attribute:
var div1Class = $('#div1').attr('class');
示例
<div id="div1" class="accordion accordion_active">
要检查上面的div中包含的类
To check the above div for classes contained in it
var a = ("#div1").attr('class');
console.log(a);
控制台输出
accordion accordion_active
这篇关于如何使用jQuery获取div的当前类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文