title: How to encode the following URL using Javascript or jQuery properly?
body: <p>All I want to do is encode the following link properly, but for some reason "#" is giving me a problem: </p>
  
  <pre><code>var text = "hello, how are you? &amp;am fine"
  var link = "http://example.com/test#zzzzzzzzz"
  
  
  url = "http://twitter.com/share?url=" + link + "&amp;text" + text;
  $("#twitter a").attr("href", url)
  </code></pre>
  
  <p>I tried <code>encodeURI</code> or <code>encodeURIComponent</code>, but still have issue with "#". If I manually replace "#" with "%23", then for some reason the code is encoded again. Does the jQuery <code>attr()</code> preform any encoding at all?</p>
  
  <p>EDIT
  Trying escape produces</p>
  
  <pre><code>http://twitter.com/share?url=http%253A//example.com/test%2523zzzzzzzz
  </code></pre>
  
  <p>Not sure where the "%25" is coming from rather than just %23</p>
  
  <p>Using <code>encodeURIComponent</code> generates the following after doing <code>$("#twitter a").attr("href", url)</code>. Where is the %25 is coming from? </p>
  
  <pre><code>http://twitter.com/share?url=http%253A%252F%252Fexample.com%252Ftest%2523zzzzzzzz
  </code></pre>