Javascript beginner: how to replace a href text if it matches a specified string?
<p>When someone posts a link to another page on my website, I'd like to shorten the a href text from something like: <code>http://mywebsite.com/posts/8</code> to <code>/posts/8</code> or <code>http://mywebsite.com/tags/8</code> to <code>/tags/8</code>. Since I'm learning javascript I don't want to depend on a library like prototype or jquery. Is it recommended to use javascript's <code>replace</code> method?</p>

<p>I found w3schools' page <a href="http://www.w3schools.com/jsref/jsref_replace.asp" rel="nofollow">here</a> but my code was replacing all instances of the string, not just the href text.</p>

<p>Here's what I have so far:</p>

<pre><code>&lt;script type="text/javascript" charset="utf-8"&gt;
  var str="http://www.mywebsite.com";
  document.write(str.replace("http://www.", ""));
&lt;/script&gt;
</code></pre>
