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

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

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

11条回答
  •  难免孤独
    2020-12-03 00:51

    Simply by

    var divClass = $("#div1").attr("class")
    

    You can do some other stuff to manipulate element's class

    $("#div1").addClass("foo"); // add class 'foo' to div1
    $("#div1").removeClass("foo"); // remove class 'foo' from div1
    $("#div1").toggleClass("foo"); // toggle class 'foo'
    

提交回复
热议问题