How can I get the current class of a div with jQuery?

后端 未结 11 476
挽巷
挽巷 2020-12-03 00:19

Using jQuery, how can I get the current class of a div called div1?

11条回答
  •  囚心锁ツ
    2020-12-03 00:45

    $('#div1').attr('class')
    

    will return a string of the classes. Turn it into an array of class names

    var classNames = $('#div1').attr('class').split(' ');
    

提交回复
热议问题