Get class list for element with jQuery

后端 未结 17 1593
粉色の甜心
粉色の甜心 2020-11-22 03:20

Is there a way in jQuery to loop through or assign to an array all of the classes that are assigned to an element?

ex.

17条回答
  •  囚心锁ツ
    2020-11-22 03:45

    Might this can help you too. I have used this function to get classes of childern element..

    function getClickClicked(){
        var clickedElement=null;
        var classes = null;<--- this is array
        ELEMENT.on("click",function(e){//<-- where element can div,p span, or any id also a class
            clickedElement = $(e.target);
            classes = clickedElement.attr("class").split(" ");
            for(var i = 0; i

    In your case you want doler_ipsum class u can do like this now calsses[2];.

提交回复
热议问题