Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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>
</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? :)

like image 444
oceanmountain Avatar asked Oct 03 '11 11:10

oceanmountain


2 Answers

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

http://jsfiddle.net/apjD6/

like image 94
davin Avatar answered Oct 01 '22 15:10

davin


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

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

like image 25
Meligy Avatar answered Oct 01 '22 14:10

Meligy