views:

24

answers:

1

How can I add http://facebook.com to relative URL's contained within #facebook_urls? Eg:

<a href="/test.html">

becomes

<a href="http://facebook.com/test.html"&gt;

#facebook_urls also contains absolute urls, so I want to make sure I don't touch those.

Thanks!

+1  A: 

Something like this?

$('#facebook_urls a').each(function() {
  if(!this.href.match('^http')) {
    this.href = "http://facebook.com/" + this.href
  }
})
Alexander Malfait
+1 but for his sample this would generate `http://facebook.com//test.html`
jitter
That should do it, thanks heaps.
Rick