开发者

Retrieve the last class in an element that has mutiple classes

How can I retrieve the last class in an element that has multiple classes assigned to it using Jquery ie.

<div class="class1 class2 class3"><开发者_运维知识库;/div>


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

alert(cls[cls.length-1]);

demo


Here's a regular expression version if you prefer.

var lastClass = $(selector).attr('class').match(/\s([^\s]+)$/)[1];


You want to retrieve class3 in this case, am I right?

var lastClassName = $.trim($("elementRef").attr("class")).split(" ").slice(-1);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜