title: Replace all images from an html string using jquery
body: <p>I have an html string from which I want to replace all my <code>img</code> tags with <code>figure</code> tag. Here is my code</p>
  
  <pre><code>$('img',$(html)).replaceWith(function(){
      var figure = '&lt;figure&gt;&lt;img src="'+$(this).src+'"&gt;&lt;figcaption&gt;'+$(this).attr('alt')+'&lt;/figcaption&gt;&lt;/figure&gt;';
      return $(figure);
  });
  </code></pre>
  
  <p>This code does not work. I would also like to return the resulting html string after the operation has been performed but it seems that replace only returns the element that has been replaced . So how do I do that?</p>