开发者

add class to <a> if href starts with http://www.twitter.com/ [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

jQuery: Select <a> which href contains some string

I am working on a little twitter implementation for a website. The javascript I use exports the code as following:

<ul>
 <li>twitter message here <a href="http://twitter.com/username/ID">time of twitter</a></li>
<开发者_Python百科;/ul>

Now I like to add a class to the twitter link, so I can give it a different css then normal links inside the tweets.

Anyone got any thoughts how to fix this in a proper way? :)


$('a[href^="http://twitter.com"]').addClass('twitter');

http://jsfiddle.net/apjD6/


$(function() {
  $("a[href^='http://twitter.com/']").addClass("someClass");
});

Check reference here:
http://api.jquery.com/attribute-starts-with-selector/

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜