title: How do I use javascript to replace hash tags with links from a jquery data-attribute
body: <p>I'm effectively trying to do the same as in this question
  <a href="https://stackoverflow.com/questions/7575041/change-hash-tag-to-link-on-page-load">Change #hash tag to link on page load</a>
  But I think because I'm getting the string from a jquery objects data-caption attribute something isn't working correctly. I have a DOM element like this</p>
  
  <pre><code>&lt;a class="thumbnail" rel="gallery" data-caption="#drink from somewhere #fun" data-pid="36" href="http://domain.com/something"&gt;&lt;img src="http://domain.com/somephoto.png" alt="acee7bd0d8339b9ddcf4a259ec7ddeec"&gt;&lt;/a&gt;
  </code></pre>
  
  <p>It's basically a thumbnail that is loaded into a modal then i'm trying to grab the attribute caption and create links out of any hash tags</p>
  
  <pre><code> var caption = anchor.attr('data-caption') ? anchor.attr('data-caption') : null;
   console.log(caption);
  </code></pre>
  
  <p>where the variable anchor is a jquery object representative of the link</p>
  
  <p>I can see there is a caption if i check the log it prints "#drink from somewhere #fun"</p>
  
  <p>So now throwing that in a regex replace fn</p>
  
  <pre><code>caption.replace(/#(\S*)/g,'&lt;a href="http://twitter.com/#!/search/$1"&gt;$1&lt;/a&gt;');
  </code></pre>
  
  <p>Then append the caption to the DOM with the links active.</p>
  
  <p>But nothing happens to the caption string I just get the same thing out that I put in.</p>
  
  <p>**EDIT ANSWER
  dumb mistake forgot to assign the return value to a variable</p>
  
  <pre><code>var captionLinks = caption.replace(/#(\S*)/g,'&lt;a href="http://twitter.com/#!/search/$1"&gt;$1&lt;/a&gt;');
  </code></pre>