jQuery and regex for adding icons to specific links?!
- by rayne
I'm using jQuery to add icons to specific links, e.g. a myspace icon for sites starting with http://myspace.com etc.
However, I can't figure out how to use regular expressions (if that's even possible here), to make jQuery recognize the link either with or without "www." (I'm very bad at regular expressions in general).
Here are two examples:
$("a[href^='http://www.last.fm']").addClass("lastfm").attr("target", "_blank");
$("a[href^='http://livejournal.com']").addClass("livejournal").attr("target", "_blank");
They work fine, but I now I want the last.fm link to work with http://last.fm, http://www.last.fm and http://www.lastfm.de. Currently it only works for www.last.fm.
I also would like to make the livejournal link work with subdomains links like http://username.livejournal.com
How can I do that? Thanks in advance!