Get first and last class with jQuery

后端 未结 7 1528
一整个雨季
一整个雨季 2021-02-09 02:58

Might be a newbie question. I have a code line like this:

I need to get each class for itself.

7条回答
  •  悲&欢浪女
    2021-02-09 03:49

    You can do this way too using map:-

    var ArrayData = $.map($(this).attr("class").split(' '), function(value){
        return value;
    });
    
    alert("first class = '"+ArrayData[0]+"'");
    alert("last class = '"+ArrayData[ArrayData.length - 1]+"'");
    

    Refer LIVE DEMO

提交回复
热议问题