title: In Javascript or jQuery, how do I detect if a specific tag exists or not?
body: <p>Given the following strings:</p>
  
  <pre><code>htmlStr1 = "&lt;img&gt;test1&lt;/img&gt;";
  htmlStr2 = "&lt;div&gt;test2&lt;/div&gt;";
  </code></pre>
  
  <p>I'd like to know if there's a way to write a function just to detect for the "img" tag (for example).  So if both of these strings are passed to it, and it should not do anything if the 2nd string is passed to it.</p>
  
  <p>so for example, you'd run a function like:</p>
  
  <pre><code>result1 = checkIfTagExists(htmlStr1, "img");
  result2 = checkIfTagExists(htmlStr2, "img");
  alert(result1); // should output "true" or "1" or whatever
  alert(result2); // should output "false" or do nothing
  </code></pre>