jQuery and regex for adding icons to specific links?!
Posted
by rayne
on Stack Overflow
See other posts from Stack Overflow
or by rayne
Published on 2010-04-23T10:37:50Z
Indexed on
2010/04/23
10:43 UTC
Read the original article
Hit count: 235
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!
© Stack Overflow or respective owner