title: Find src attribute value of <img> tag in a Javascript string
body: <p>I have been trying to get the 'src' in img tags inside a javascript variable that contains a block of HTML code dynamically generated/assigned.</p>
  
  <p>Eg:</p>
  
  <pre><code>var post_body = "&lt;div&gt;This is an image &lt;img src='abcd.jpg' /&gt; and this is a paragraph &lt;p&gt;hi there&lt;/p&gt; Here we have another image &lt;img src='pqrs.jpg' /&gt;&lt;/div&gt;"
  </code></pre>
  
  <p>the content of the 'post' variable is not predefined and it is dynamic and the HTML code in it always changes. To get the src of the image in it, I did the following. But it does not always work for me.</p>
  
  <pre><code>var firstimg = $(post_body).find("img:first").attr("src");
  </code></pre>
  
  <p>I was trying to get the first image of a blog post from the blog post's content but this does not work for some posts having images. How can this be done using javascript or jQuery without failing?</p>