jQuery - find last class on the element

后端 未结 2 1072
醉酒成梦
醉酒成梦 2020-12-10 11:17

How to find last class on the element without knowing exact number of classes?

Our element:

 
&l
2条回答
  •  无人及你
    2020-12-10 11:45

    The simplest solution is to use pop, which accesses the last element in the array.

    var lastClass = $('div').attr('class').split(' ').pop();
    

    Note that pop also removes the element from the array, but since you aren't doing anything else with it, that's not a problem.

提交回复
热议问题