title: Javascript to convert html to bbcode, for images with links
body: <p>I have a image gallery made in php. I have made a little php script that generates a code with my latest uploaded pictures, a list of thumbnails that have a structure like this (I can change the structure if needed):</p>
  
  <pre><code>&lt;div class="thumbs"&gt;
  &lt;img src="http://placehold.it/100x100" alt="http://example.com/picture1.php" class="bbcode" /&gt;
  &lt;img src="http://placehold.it/99x99" alt="http://example.com/picture2.php" class="bbcode" /&gt;
  &lt;/div&gt;
  
  &lt;textarea class="message" rows="10" cols="60"&gt;
  
  &lt;/textarea&gt;
  </code></pre>
  
  <p>DEMO <a href="https://jsfiddle.net/xwhg3nch/" rel="nofollow">https://jsfiddle.net/xwhg3nch/</a></p>
  
  <p>I need a javascript (can be based on any JS library) that when I click a picture to create a BBCODE image with link for it in my textarea, example:</p>
  
  <pre><code>[url=http://example.com/picture1.php][img]http://placehold.it/100x100[/img][/url]
  [url=http://example.com/picture2.php][img]http://placehold.it/99x99[/img][/url] 
  </code></pre>
  
  <p>and put a small border around the picture (for me to see that I already clicked that picture).</p>
  
  <p>Thanks</p>