开发者

Apply CSS based on text length of <a href="">

If a href is longer than 40 chars I want apply a class to the p开发者_JAVA技巧revious LI element.

How can I do this in jQuery?


Try this:

$('li a').filter(function () {
    return $(this).attr('href').length > 40;
}).closest('li').addClass(...);

Demo here: http://jsfiddle.net/BPQBe/1

Further reading:

  • filter()
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜